Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
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
add comment

2 Answers 2

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
add comment

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: tldp.org/LDP/abs/html/functions.html –  Matthieu Cartier Jan 8 '11 at 19:46
1  
@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: efreedom.com/Question/3-105375/Bash-Spaces-Alias-Name 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
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.