Reputation: 255
I'm trying to construct a path using a command-line argument in bash. I added the following line to my .bashrc:
alias hi="echo '/path/to/$1'"
However, this yields:
~$ hi foo
/path/to/ foo
Any idea where the blank after the slash is coming from?
Thanks
Hannes
Upvotes: 1
Views: 237
Reputation: 360065
As Lukáš Lalinský stated, aliases don't take arguments, so $1
is null. However, even if you were to do this:
alias hi="echo '/path/to/'"
you'd get a space. The reason for this is so that if you had an alias like this:
alias myls=ls
and did:
myls filename
it wouldn't try to run:
lsfilename
Upvotes: 1
Reputation: 41306
In short, aliases can't take arguments. You can make a function instead:
$ function hi() { echo "/path/to/$1"; }
$ hi foo
/path/to/foo
Read here for other options.
Upvotes: 5