0

Why doesn't the alias work, but the function does works inside my .bash_profile?

Code inside .bash_profile (below)

alias pxsz='sips -g pixelWidth $1 && sips -g pixelHeight $1'

pxlsz () {
    sips -g pixelWidth $1 && sips -g pixelHeight $1
}

When I tested the alias with

alias pxsz="echo '$1 1' && echo '$1 2' "

gives

 $pxsz tag_struct.jpg
1
2 tag_struct.jpg
J. Chomel
  • 8,193
  • 15
  • 41
  • 69
Scott Hom
  • 9
  • 1

1 Answers1

0

You can't use a variable inside an alias like this. Here you just call to the $1 that must be defined beforehand in your shell, and it is the previous first argument of previous command:

$ set TEST
$ echo $1
TEST
$ alias pxsz="echo '$1 1' && echo '$1 2' "
$  pxsz
TEST 1
TEST 2

The function, like you did, is the way to go.

J. Chomel
  • 8,193
  • 15
  • 41
  • 69