Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cmcl2!uupsi!sunic!ugle.unit.no!news From: Harald.Eikrem@elab-runit.sintef.no Newsgroups: comp.unix.shell Subject: Re: Delayed evaluation of csh variables? Message-ID: <90Dec13.031710*Harald.Eikrem@elab-runit.sintef.no> Date: 13 Dec 90 02:17:10 GMT References: , <110255@convex.convex.com>, Sender: news@ugle.unit.no Organization: ELAB-RUNIT (SINTEF), Trondheim, Norway. Lines: 112 I believe there are cases when csh outperforms Bourne shell, e.g. when you are on a slow system and need access to expression evaluation, exemplified by: ========= #!/bin/csh -f # pickcolor - pick an X application background color semirandomly if ( $#argv == 0 ) then set argv=( BlanchedAlmond Bisque NavajoWhite YellowGreen \ BlanchedAlmond Honeydew2 Tan LightSalmon LavenderBlush \ MistyRose Moccasin LightSteelBlue NavajoWhite PaleTurquoise \ BlanchedAlmond Khaki PaleGoldenrod Lavender Tan Salmon \ Orchid Seashell3 PaleVioletRed Thistle NavajoWhite Wheat ) endif set pick=1 if ( $#argv > 1 ) then /usr/games/random -e $#argv @ pick = $status + 1 endif echo $argv[$pick] ========= For a different case, save the following as ~/csh/path and then alias path source ~/csh/path "'\!*'" then you have a simple csh $path manipulator. I like to see this done for ksh/bash...... --Harald E ========= # csh search path management procedure # - invoke through alias path source path "'\!*'" # if ( ! $?path ) set path = "" if ( "$path" == '' && '!*' !~ [./~]* && '!*' !~ \$?* ) then set path = (. ~/bin /usr/local/bin /usr/ucb /bin /usr/bin) echo 'No path set; using default settings.\ '$path else if ( '!*' == '' ) then echo $path else if ( '!*' == '-' || '!*' == '-$' ) then if ( $#path == 1 ) then echo 'Only one path element left, will not unset $path' else @ n__ = $#path - 1 set path = ($path[-$n__]) echo $path endif unset n__ else if ( '!*' == '-^' ) then if ( $#path == 1 ) then echo 'Only one path element left, will not unset $path' else set path = ($path[2*]) echo $path endif unset n__ else if ( '!*' =~ \-[1-9] || '!*' =~ \-[1-9][0-9] ) then @ arg__ = - !^ if ( $arg__ > $#path ) then if ( $#path == 1 ) then echo 'There is currently only '$#path' element in $path' else echo 'There are currently '$#path' elements in $path' endif else if ( $#path == 1 ) then echo 'Only one path element left, will not unset $path' else if ( $arg__ == $#path ) then @ n__ = $arg__ - 1 set path = ($path[-$n__]) echo $path else @ n__ = $arg__ - 1 @ r__ = $arg__ + 1 set path = ($path[-$n__] $path[$r__-]) echo $path endif unset arg__ n__ r__ else if ( '!*' =~ [1-9^]\ [./~]* || '!*' =~ [1-9][0-9]\ [./~]* || \ '!*' =~ [1-9^]\ \$[_a-zA-Z0-9]* || \ '!*' =~ [1-9][0-9]\ \$[_a-zA-Z0-9]* ) then if ( !^ > $#path + 1 ) then if ( $#path == 1 ) then echo 'There is currently only '$#path' element in $path' else echo 'There are currently '$#path' elements in $path' endif else if ( !^ <= 1 || !^ == ^ ) then set path = (!:2* $path) echo $path else if ( !^ > $#path ) then set path = ($path !:2*) echo $path else @ r__ = !^ - 1 set path = ($path[-$r__] !:2* $path[!{^}*]) echo $path endif unset arg__ n__ r__ else if ( '!*' =~ [./~]* || '!*' =~ \$[_a-zA-Z0-9]* ) then set path = ($path !*) echo $path else echo 'Usage: path { -^ | -$ | - | - | pathname(s) | pathname(s) }\ meaning:\ -^ strip first element from $path.\ -$ or - strip last element.\ - strip element number , numbering from 1 up.\ pathname(s) insert pathname(s) before element , where\ can be ^ if before first element.\ pathname(s) add pathname(s) beyond last element.\ \ A valid pathname should start with [./~], or be a shell variable constituting\ one or more valid pathnames.' endif