Korn shell Tutorials :Regular Expressions
Ksh has it's own regular expressions.
Use an * for any string. So to get all the files ending it .c use *.c.
A single character is represented with a ?. So all the files starting with any sign followed bye 44.f can be fetched by: ?44.f.
Especially in ksh there are quantifiers for whole patterns:
?(pattern) matches zero or one times the pattern.
*(pattern) matches any time the pattern.
+(pattern) matches one or more time the pattern.
@(pattern) matches one time the pattern.
!(pattern) matches string without the pattern.
So one can question a string in a variable like: if [[ $var = fo@(?4*67).c ]];then ...
Showing posts with label ksh scripting. Show all posts
Showing posts with label ksh scripting. Show all posts
Korn shell Tutorials :Comparision in scripting
Korn shell Tutorials :Comparision in scripting
To compare strings one uses "=" for equal and "!=" for not equal.
To compare numbers one uses "-eq" for equal "-ne" for not equal as well as "-gt" for greater than
and "-lt" for less than.
if [[ $name = "John" ]];then
# commands....
fi
if [[ $size -eq 1000 ]];then
# commands....
fi
With "&&" for "AND" and "||" for "OR" one can combine statements:
if [[ $price -lt 1000
$name = "Hanna" ]];then
# commands....
fi
if [[ $name = "Fred" && $city = "Denver" ]];then
# commands....
fi
To compare strings one uses "=" for equal and "!=" for not equal.
To compare numbers one uses "-eq" for equal "-ne" for not equal as well as "-gt" for greater than
and "-lt" for less than.
if [[ $name = "John" ]];then
# commands....
fi
if [[ $size -eq 1000 ]];then
# commands....
fi
With "&&" for "AND" and "||" for "OR" one can combine statements:
if [[ $price -lt 1000
$name = "Hanna" ]];then
# commands....
fi
if [[ $name = "Fred" && $city = "Denver" ]];then
# commands....
fi
Subscribe to:
Posts (Atom)