Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create an alias in bash for example:

alias cat /home/file='cat /home/thisfile'

I have no idea why this is not working. I have tried everywhere to find the answer on google and from what I can tell this website will get the answer. -Janice

share|improve this question
Are you sure a symlink wouldn't be the better solution? – Daniel Beck Jan 8 '11 at 19:35
Hello Daniel, in this case no. – Janice Young Jan 8 '11 at 19:37

You can use aliases only for commands, not for their arguments.

If you want /home/file to be replaced by /home/thisfile, but only if it's the first argument of the cat command, you can define a cat function that tests its argument and calls the underlying command appropriately:

cat () {
  if [ "$1" = "/home/file" ]; then shift; set "/home/thisfile" "$@"; fi
  command cat "$@"

But I doubt that's what you really want, it would be a strange requirement. Daniel Beck's suggestion of a symbolic sounds right. Since you reject it, you should explain more of what you're trying to accomplish. Maybe then people can offer better suggestions.

share|improve this answer
Gilles, your command worked perfectly! I guess i better study up on function calls, etc. You, the other users, and this website are lifesavers. Thanks ~ =0) – Janice Young Jan 8 '11 at 20:33

You can't have an alias that contains two words, use a function instead and use awk to separate the captures.

share|improve this answer
Hello Neurolysis, can you please explain? – Janice Young Jan 8 '11 at 19:41
My regex is pretty bad, so I'd rather not post an example that specifically relates to this case (because in all likelihood I'll get it wrong). There is some pretty good documentation to get you started though: – Matthieu Cartier Jan 8 '11 at 19:46
@Janicem it looks like you are trying to make an alias for cat /home/file, aliases can only be a single word, no spaces, see this question – heavyd Jan 8 '11 at 19:46
ok thanks the last portion to this is a post from: is there any way to incorporate it like that? or am I way off course?. Thank you. Janice – Janice Young Jan 8 '11 at 19:47
Oh yes, if you're asking about aliases, aliases can only be a single word. I assumed you were asking about functions. – Matthieu Cartier Jan 8 '11 at 19:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .