1

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

2 Answers2

5

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.

2

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