#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Orlando FL
    Posts
    130
    Rep Power
    13

    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.
    Help me, help you, help others...
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Orlando FL
    Posts
    130
    Rep Power
    13
    Can someone here help or give little suggestio?
    Help me, help you, help others...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    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...

    [edit]
    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/
    [/edit]
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Orlando FL
    Posts
    130
    Rep Power
    13
    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.
    Help me, help you, help others...
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    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\)$"
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Orlando FL
    Posts
    130
    Rep Power
    13
    ahh , ur quote will work in ksh but not in tcsh... strange tcsh huh?, well that works for me. Thanks!!!
    Help me, help you, help others...
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    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
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Orlando FL
    Posts
    130
    Rep Power
    13
    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!
    Help me, help you, help others...
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    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?
  18. #10
  19. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Orlando FL
    Posts
    130
    Rep Power
    13
    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.
    Help me, help you, help others...

IMN logo majestic logo threadwatch logo seochat tools logo