Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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
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:
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
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 ?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.