Helpful Information
 
 
Category: UNIX Help
Escape ' or tick mark in tcsh

Hi, I wanted to setup a simple alias for this command:


tiger[zdeng]% ls -F |egrep '\/$'
MyNetBoss/
MyTigerServer/
mywork/
nsmail/
tiger[zdeng]%


as you can see, the out put of this command run just fine. but when I create a alias in my login script, it's imposible to escape the back tick. I have tried the following but failed.

tiger[zdeng]% alias test 'ls -F |egrep "\/$"'
tiger[zdeng]% test
Illegal variable name.
tiger[zdeng]%

Any idea? Thanks.

Can someone here help or give little suggestio?

i tried, but i could not make it work either :(

one hint: i think you have to escape the "$" somehow, not the quotes or ticks as replacing by "$1" eg. does work. (but with the wrong result of course...)

\$ did not work though...


aaah, i got it :)
you must not use quotes for the egrep parameter. if you want to use spaces, escape them instead.
in the tcsh manual i read that a "$" at the end of a line is NEVER passing "variable substitution" and something about aliases having several passes for substitution (what probably caused your problem).

so it is:
# alias test 'ls -F |egrep \/\$'
# test
.emacs.d/
.gconf/
.gconfd/
.gnome/
.gnome_private/
.kde/
.mc/
.mcop/
.qt/
.sawfish/
.ssh/
Desktop/

thx for reply M.Hirsch,

This only solve half of the problem. If I can't use the tick or quote in my egrep command , then I have problem with little more complicated expression such as this one.

tiger[zdeng]% %ls -F | egrep '(/|rc)$'
MyNetBoss/
MyRecycleBin/
local.cshrc
mywork/
nsmail/
tiger[zdeng]%

It will not work if I leave out the quote:
tiger[zdeng]% ls -F | egrep (/|rc)$
Badly placed ()'s.
tiger[zdeng]%

So how can I put it in the alias. The '$' is used for expression, not var substitution in shell.

thanks.

from the tcsh manual:


variable substitution is performed keyed by `$' characters

and your error message made me assume this.

For the new problem: it does not like the brackets, so escape them. (it will probably not like the pipe either)

alias test="ls -F | egrep \(/\|rc\)$"

ahh , ur quote will work in ksh but not in tcsh... strange tcsh huh?, well that works for me. Thanks!!! :)

really strange tcsh, as it does work for me
# set|grep version
tcsh 6.11.00 (Astron) 2001-09-02 (i386-intel-FreeBSD) options 8b,nls,dl,al,kan,sm,rh,color,dspm


Help me, help you, help others...
i like your attitude ;)

yes, it does work! my mistake.

alias test="ls -F | egrep \(/\|rc\)$"

will not work in tcsh shell because the equal sign and the double quote. it will work if I do this:

alias test 'ls -F | egrep \(/\|rc\)$'

Here is my test result:
tiger[zdeng]% set | grep version
version tcsh 6.10.00 (Astron) 2000-11-19 (sparc-sun-solaris) options 8b,nls,dl,al,rh,color
tiger[zdeng]% alias test="ls -F | egrep \(/\|rc\)$"
Illegal variable name.
tiger[zdeng]% alias test "ls -F | egrep \(/\|rc\)$"
Illegal variable name.
tiger[zdeng]% alias test 'ls -F | egrep \(/\|rc\)$'
tiger[zdeng]% test
MyNetBoss/
MyRecycleBin/
local.cshrc
mywork/
nsmail/
tiger[zdeng]%

You have been great help. Thx again!

oops, not your mistake, but mine. i should cut-n-paste, not test-n-write-from-memory. i did not use the equal-sign nor double-quotes either...

for my own scripting, i am using bash which is the most powerful shell iīve ever seen. but itīs a matter of personal choice. bash needs quite some ressouces (as eg. i failed to run it on a 386-40/8MB)

...i am happy when i can make other people happy... show your gratitude by staying around and helping others too :)

solaris on a sparc station... whew, are you a unix professional?

I sure will Hirsch. My signiture is ...

Help me, help you, help others... remember? ;) he eh

well, I started a new job as a system integrator engineer at Harris Inc... I deal with Harris's OSS products that must run on Sun Solaris 8. http://www.netboss.harris.com

I am learning lots of UNIX like stuff and it's interest me.

Later buddy.










privacy (GDPR)