Schell Script Reference
Path Modification
CSH
:r Remove last suffix
:h Remove last / and after
:t Remove last / and before
:e Remove last . and before
$?<variable name> - variable is set?
Input value from stdin
CSH
set <variable name>=$<
SH
read <variable name>
readonly <variable name>
Position Parameter
CSH
Array
set <variable name>=(value1 value2 value3 ...)
from <variable name>[1] is set
$#<variable name> provide the number of variable
% <script file name> arg1 arg2 arg3
$0 $1 $2 $3
$argv[1]$argv[2]$argv[3]
all argument $* or $argv
number of argument $#argv
SH
Set the value from position parameter
set value1 value2 value3
$1 $2 $3
% <script file name> arg1 arg2 arg3
$0 $1 $2 $3
all argument $*
number of argument $#
Command exit situation
CSH
{ <command> } true if normal exit(0)
SH
test <condition expression> true if normal exit(0)
[ <condition expression> ] true if normal exit(0)
Input and Output
CSH
>, <, >>
>& stdout and stderr
SH
>, <, >>
2> stderr
> file 2>&1 stdout and stderr
Calculation
CSH
@ <variable name> = expression
>> <number of shift> bit shift
~ complement of 1
! logical no
| bit level or
^ bit level exclusive or
& bit level and
|| logical sum
&& logical survey
SH
<variable name> = `expr expression`
-a logical survey
-o logical sum
! logical no
String literal
CSH
== equal
!= not equal
=~ equal and enable meta character
!~ not equal and enable meta character
SH
= equal
!= not equal
<String> - true if not null
-z <String> - true if 0
-n <String> - true if not 0
Integer
CSH
==, !=, >, <, >=, <=
SH
-eq, -ne, -gt, -ge, -lt, -le
File Type Check
CSH
-r true if read
-w true if write
-x true if execute
-e true if exist
-o true if owner
-f true if normal
-z true if 0 size
-d true if directory
SH
-r true if read
-w true if write
-f true if normal
-s true if size is not 0
-d true if directory
Condition Branch
CSH
if ( expression ) then
command list
else if ( expression ) then
command list
else
command list
endif
switch ( character set )
case pattern:
command
breaksw
case pattern:
command
breaksw
default:
command
breaksw
endsw
SH
if test command
then
command list
else
command list
fi
if test command; then command list; else command list; fi
case word in
pattern)
command list
;;
pattern)
command list
;;
esac
Loop
CSH
foreach <variable name> ( value1 value2 value3 ... )
command list
end
while ( expression )
command list
end
goto <label name>
shift <array variable name>
break end loop
continue back to top of the loop
exit(<value>) end of execution
SH
for <variable name> in value1 value2 value3 ...
do
command list
done
while test command
do
command list
done
until test command
do
command list
done
shift <array variable name>
break end loop
continue back to top of the loop
exit <value> end of execution