LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   linux ALIAS name cant include "\" escape ?! (http://www.linuxquestions.org/questions/linux-software-2/linux-alias-name-cant-include-%5C-escape-759535/)

stu7 10-04-2009 02:41 AM

linux ALIAS name cant include "\" escape ?!
 
Ive used escaped characters for ten years in linux ALIASES...
but now, when I try to write an alias such as the following...

alias "\?boofar"='cd /home/boofar' I get error msgs
loading the file, and of course the alias wont work.

even though the Bash manual suggests escaping special
characters with the backslash, it breaks the alias...
and Im not seeing any other way to do this.

Anyone know how to get around this, or fix it ?

thanks for reading

lutusp 10-04-2009 03:29 AM

Quote:

Originally Posted by stu7 (Post 3706842)
Ive used escaped characters for ten years in linux ALIASES...
but now, when I try to write an alias such as the following...

alias "\?boofar"='cd /home/boofar' I get error msgs
loading the file, and of course the alias wont work.

even though the Bash manual suggests escaping special
characters with the backslash, it breaks the alias...
and Im not seeing any other way to do this.

Anyone know how to get around this, or fix it ?

thanks for reading

This works for me from the command line:

alias "?xx"='cd path'

Quote:

Originally Posted by stu7 (Post 3706842)
I get error msgs loading the file,

What file would that be? What error messages?

If you are placing these alias definitions in a shell script and you expect them to take effect after the script exits, you have to execute the script this way:

. path-to-script (see the dot at the left?)

slakmagik 10-04-2009 05:15 AM

He was escaping with a backslash and quoting, so getting

bash: alias: `\?boofar': invalid alias name

Either quoting or escaping works.

Shadow_7 10-04-2009 12:14 PM

To bypass an alias, you prefix the command with \. Perhaps that's the issue. Maybe a \\ would escape the escape for you. Or just leave it out as it might be irrelevant for an alias. Or maybe the rules of the game changes POSIX compliance. I'm not that adept at aliases, outside of bypassing them when they don't make sense for me. Like dark blue colors on a black background. \ls

stu7 10-04-2009 07:26 PM

Quote:

Originally Posted by slakmagik (Post 3706954)
He was escaping with a backslash and quoting, so getting

bash: alias: `\?boofar': invalid alias name

Either quoting or escaping works.

slakmagik - thanks for that explanation... exactly what Im getting. Here is the problem alias as written in my file: alias "\/"='cd /'
which gives me the error you mentioned.

I have, however, tried quoting, using either single or double quotes, and, with or without any back-slash for escapes... but the same error occurs.
Possibly there is some
issue with writing any alias including the forward slash character, since that is also a [reserved] directory name ?

i92guboj 10-04-2009 10:31 PM

Quote:

Originally Posted by stu7 (Post 3707697)
slakmagik - thanks for that explanation... exactly what Im getting. Here is the problem alias as written in my file: alias "\/"='cd /'
which gives me the error you mentioned.

I have, however, tried quoting, using either single or double quotes, and, with or without any back-slash for escapes... but the same error occurs.
Possibly there is some
issue with writing any alias including the forward slash character, since that is also a [reserved] directory name ?

It's clearly stated in the man page.

Quote:

Originally Posted by bash man page
ALIASES
Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. The shell maintains a list of aliases that may be set and unset with the alias and unalias builtin commands (see SHELL BUILTIN COMMANDS below). The first word of each simple command, if unquoted, is checked to see if it has an alias. If so, that word is replaced by the text of the alias. The characters /, $, `, and = and any of the shell metacharacters or quoting characters listed above may not appear in an alias name. The replacement text may contain any valid shell input, including shell metacharacters.

PS: You might want to check the "autocd" shopt option. You don't need an alias for this. The option is modern though, so you will need to update bash if you are not using 4.x already.

stu7 10-05-2009 03:17 PM

Thank you so much !

Nothing more fruitless than trying to do what Linux
is built NOT to do : - )


All times are GMT -5. The time now is 04:54 PM.