Hi folks. Can someone tell me how I would declare a variable that has an OR statement. For example under date variable I want a OR:
#!/usr/bin/ksh
date=$((05 | 06 | 07))
CURRDATE=$(date +%d)
if [[ "$date" = "$CURRDATE" ]]
then
echo true
else
echo false
fi
The syntax for an OR test using KSH pattern is :
if [[ "$CURRDATE" = @(05|06|07) ]]
You can try to put the OR pattern in a variable (not tested) :
#!/usr/bin/ksh
date=@(05|06|07)
CURRDATE=$(date +%d)
if [[ "$CURRDATE" = $date ]]
then
echo true
else
echo false
fi
Jean-Pierre.
***deleted to avoid confusion.
This syntax is not ksh93 specific.
The following lines comes from the ksh88 man pages :
File Name Generation
Following substitution, each command word is scanned for the characters *, ?, and [
unless the -f option has been set.
If one of these characters appears then the word is regarded as a pattern.
The word is replaced with lexicographically sorted file names that match the pattern.
If no file name is found that matches the pattern, then the word is left unchanged.
When a pattern is used for file name generation, the character . at the start of a file name
or immediately following a /, as well as the character / itself, must be matched explicitly.
In other instances of pattern matching the / and . are not treated specially.
* Matches any string, including the null string.
? Matches any single character.
[ . . . ] Matches any one of the enclosed characters. A pair of characters separated
by - matches any character lexically between the pair, inclusive.
If the first character following the opening "[ " is a "! " then any character not enclosed
is matched.
A - can be included in the character set by putting it as the first or last character.
A pattern-list is a list of one or more patterns separated from each other with a |.
Composite patterns can be formed with one or more of the following:
?(pattern-list ) Optionally matches any one of the given patterns.
*(pattern-list ) Matches zero or more occurrences of the given patterns.
+(pattern-list ) Matches one or more occurrences of the given patterns.
@(pattern-list ) Matches exactly one of the given patterns.
!(pattern-list ) Matches anything, except one of the given patterns.
Sorry Jean-Pierre,
You are correct. I wasn't thinking straight when I posted that, to avoid confusion I have removed the test from that post.