KSH - Korn Shell Tutorial
KSH - Korn Shell Tutorial
htm
Search: The Web Tripod Report Abuse « Previous | Top 100 | Next »
share: del.icio.us | digg | reddit | furl | facebook
Ads by Google
Matching Patterns
Conditional Statements
1 of 5 1/30/2009 8:35 PM
KSH - Korn Shell Tutorial http://b62.tripod.com/doc/docksh.htm
directory -d
plain file -f
symbolic link -h
named pipe -p
block special file -b
character special file -c
soft link -L
socket -S
owned by me -O
owned by my group not
2 of 5 1/30/2009 8:35 PM
KSH - Korn Shell Tutorial http://b62.tripod.com/doc/docksh.htm
POSITIONAL PARAMETER
REDIRECTIONS
0 stdin
1 stdout
2 stderr
Examples:
cmd 2>/dev/null
cmd >/dev/null 2>&1
exec 1<&- # close descriptor 1
exec 2<&- # close descriptor 2
exec 1< /dev/null # open descriptor 1
exec 2< /dev/null # open descriptor 2
OTHER FUNCTIONALITIES
V1=${V2:=V3} Set V1 with the value of V2 if this is set else set the
variable V1 with value of V3 (V3 could be a number).
sh replacement: if [ $V2 ] ; then
V1=$V2
else
V1=$V3
Example: DisplaySize=${LINES:24} ; Command=${Command:"cat"}
${V1:?word} if V1 set & V1!=null ret $V1 else print word and exit
: ${V1:?"variable V1 not set on null"}
${V1:=word} if V1 !set | V1==null set V1=$word
${V1:-word} if V1 set & V1!=null ret $V1 else ret word
${V1:+word} if V1 set & V1!=null ret word else ret nothing
${V1##patt}
3 of 5 1/30/2009 8:35 PM
KSH - Korn Shell Tutorial http://b62.tripod.com/doc/docksh.htm
${V1#patt} if patt are found at the begin of V1 return V1 whitout the patt
else return V1
V1="lspwd" ; ${V1#"ls"} # exec pwd
${V1%%patt}
${V1%patt} if patt are found at the end of V1 return V1 whitout the patt
else return V1
V1="lspwd" ; ${V1%"pwd"} # exec ls
COPROCESS
L' esempio dimostra come l'input e' passato verso e ritornato da un coprocess:
echo "Initial process"
./FileB.sh |&
read -p a b c d
echo "Read from coprocess: $a $b $c $d"
print -p "Passed to the coprocess"
read -p a b c d
echo "Passed back from coprocess: $a $b $c $d"
FileB.sh
echo "The coprocess is running"
read a b c d
echo $a $b $c $d
L'output risultante e' il seguente:
Initial process
Read from coprocess: The coprocess is running
Passed back from coprocess: Passed to the coprocess
EXAMPLES
- exec
REGULAR EXPRESSION
4 of 5 1/30/2009 8:35 PM
KSH - Korn Shell Tutorial http://b62.tripod.com/doc/docksh.htm
VAR="-ciao"
RESULT=`expr "$VAR" : "-\(.\)"`
echo $RESULT .. -c
- toglie il '-' iniziale
VAR="-ciao"
VAR=`expr "$VAR" : "-*\(.*\)"`
echo $VAR .. ciao
- ritorna la lunghezza di una stringa
VAR="ciao"
echo `expr length $SHELL` .. 4
- ritorna l'indice di dove incontra una substringa
echo `expr index abcdef de` .. 4
- ritorna 6 caratteri a partire dall'11
expr substr "Goodnight Ladies" 11 6 .. Ladies
ARRAY
- definisce un array
set -A Week Sat Sun Mon Tue Wed Thu Fri
- ritorna un elemento dell'array
echo ${Week[3]} .. Tue
id=3 ; echo ${Week[id]} .. Tue
- stampa tutti gli elemti di un array
echo ${Week[@]} .. Sat Sun Mon Tue Wed Thu Fri
- scandisce un array
for day in ${Week[@]}
do
echo $day
done
- ritorna il numero di elementi in un array
nelem=${#Week[@]} ; echo $nelem .. 7
Home Company Products Services Works Resources Sales Support News Search Map © Design by
Ads by Google
Unix Shell Script Shell Scripting Learn shell by examples Fine China Replacements
Save on Computer Books Compare & Register Now & Get the Job You Want Learn more from educational shell Replacements.com carries thousands
Buy from 1000s of Stores Dice - Career Hub for Tech Insiders programming screencasts of fine china patterns, old and new
www.Shopping.com www.Dice.com shellshore.com www.replacements.com/
5 of 5 1/30/2009 8:35 PM