Subject: ksh patterns
To: None <netbsd-users@netbsd.org>
From: Martin Bock <ixel@gmx.de>
List: netbsd-users
Date: 09/19/2007 18:36:52
Hello!
I am having trouble to understand ksh behaviour in context of patterns,
parameters and the case-statements:
The following is what I expected:
------------------------------------------------
$ cat script1.sh
#!/bin/ksh
for file in foo bar baz; do
case $file in
foo) echo foo;;
baz|bar) echo ba;;
*) echo default;;
esac
done
$ ksh script.sh
foo
ba
ba
------------------------------------------------
But with a minor modification it does not work as expected:
------------------------------------------------
$ cat script2.sh
#!/bin/ksh
foopattern="foo"
bapattern="baz|bar"
for file in foo bar baz; do
case $file in
$foopattern) echo foo;;
$bapattern) echo ba;;
*) echo default;;
esac
done
$ ksh script2.sh
foo
default
default
------------------------------------------------
Note the parameters containing the patterns for the case statement.
Apparently the | symbol does not do the desired magic within paramters.
Now, where is the meaning of the | as in script1.sh explained in ksh(1)?
While very common usage, I could not seem to find it after several reads
of that manpage.
Why does the version in script2.sh not work? In particular the patterns
before ) in the case statement are -- according to ksh(1) -- subject to
parameter expansion.
VWIW, this is NetBSD 3.1
Best regards, Martin
--
Martin Bock :wq