LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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

Reply
 
Search this Thread
Old 10-04-2009, 01:41 AM   #1
stu7
Member
 
Registered: Jun 2007
Posts: 88

Rep: Reputation: 15
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
 
Old 10-04-2009, 02:29 AM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by stu7 View Post
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 View Post
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?)
 
Old 10-04-2009, 04:15 AM   #3
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
He was escaping with a backslash and quoting, so getting

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

Either quoting or escaping works.
 
Old 10-04-2009, 11:14 AM   #4
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 1,524

Rep: Reputation: 235Reputation: 235Reputation: 235
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
 
Old 10-04-2009, 06:26 PM   #5
stu7
Member
 
Registered: Jun 2007
Posts: 88

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by slakmagik View Post
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 ?

Last edited by stu7; 10-04-2009 at 06:29 PM.
 
Old 10-04-2009, 09:31 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Quote:
Originally Posted by stu7 View Post
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.

Last edited by i92guboj; 10-04-2009 at 09:37 PM.
 
Old 10-05-2009, 02:17 PM   #7
stu7
Member
 
Registered: Jun 2007
Posts: 88

Original Poster
Rep: Reputation: 15
Thank you so much !

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


Reply

Tags
alias, characters, linux, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem "$value=`mpstat 1 1 | grep "Average"`;" Alias pipe return nothing adamlucansky Linux - General 8 09-25-2009 07:26 AM
[SOLVED] alias startdwm="export MYWM=dwm & startx" Mol_Bolom Programming 1 07-12-2009 02:21 AM
Linux server spitt's out my "include" files payjoe Linux - Newbie 1 12-15-2007 12:16 PM
SuSE 9.3 Pro boots NICs alias "randomly" each boot HellSpawn Linux - Hardware 0 07-04-2006 10:50 AM
bash equivalence of tcsh "alias em "emacs \!:1 &""? rgiggs Slackware 3 07-29-2004 02:07 AM


All times are GMT -5. The time now is 08:41 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration