tags:

views:

69

answers:

2

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

+3  A: 

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.

Lukáš Lalinský
Thanks! Guess that's what I was looking for.
Hannes
A: 

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
Dennis Williamson