Strange behavior in Korn shell script
- From: Norman Bullen <norm@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Feb 2006 01:55:59 GMT
I'm writing a Korn shell script and have encountered a behavior that I cannot explain. Perhaps someone else can.
The script contains something like the following:
xxx | sort |
while read count i rgID
do
if (( alloc < N ))
then
grep NEXT_LUN_$i_$rgID /tmp/alloc.LUNlist.txt | read id LUN
(( alloc += 1 ))
fi
done
(xxx represents a rather complicated loop that prints lines with three fields on each. Each of the fields is a decimal number, with the first being right-aligned to facilitate the sort. That output has been examined and found to be correct. This is sorted on the first field and read by the "read" statement in this loop.)
What I cannot explain is the "grep" statements that are generated. I expect something like
grep NEXT_LUN_4_7 /tmp/...
where "4" and "7" are the value of fields that were read. There should be two words, two numbers, and three "_" characters separating them.
What I see when I have trace mode turned on is:
grep NEXT_LUN_7 /tmp/...
It's as if one of the numbers and a "_" have been ignored.
I changed the "_" characters to "." characters and I get what I expect:
grep NEXT.LUN.4.7 /tmp/...
After an appropriate change to the script component (an awk script) that generates /tmp/alloc.LUNlist.txt everything works as I expect.
But why did it not work with the underscore characters? Is "_" somehow special to Korn shell? (I can't find any reference to it in my book.)
Norm
--
--
To reply, change domain to an adult feline.
.
- Follow-Ups:
- Re: Strange behavior in Korn shell script
- From: Dan Mercer
- Re: Strange behavior in Korn shell script
- Prev by Date: Top 10 subjects comp.unix.shell
- Next by Date: Re: ((...)) vs [...]
- Previous by thread: Re: Shell looking in mysterious places for the svn execute file
- Next by thread: Re: Strange behavior in Korn shell script
- Index(es):
Relevant Pages
|
|