Re: Strange behavior in Korn shell script



Dan Mercer wrote:

"Norman Bullen" <norm@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:P_sMf.1259$6I.1182@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
: 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
grep NEXT_LUN_${i}_${rgID} /tmp/alloc.LUNlist.txt | read id LUN

"_" is a legal variable name character which are [_A-Za-z][_A-Za-z0-9]*

You your script is evaluating $i_ and finding it blank.

Dan Mercer

: (( 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.
:


Thanks for that.

--
--
To reply, change domain to an adult feline.

.



Relevant Pages

  • Re: Running a job in AIX
    ... command to show what is in the queue, ... we create a short script that sets our environment ... into an sql table, then runs an sql procedure to process the data in ... I would recommend that you get a copy of "Learning the Korn Shell" from ...
    (comp.unix.aix)
  • Re: arithmetic substitution in while loop in MKS Korn shell
    ... the MKS Korn shell is supposed to be compatible with ksh93. ... I modified the script by adding $'s to the arithmetic ... and doesn't find the command. ...
    (comp.unix.shell)
  • Re: schedule a task to run a korn shell script
    ... >>I need to schedule a task to run a korn shell ... This is UNIX CHRON jobs, or CRON jobs? ... command script right into it. ...
    (comp.unix.questions)
  • Re: How to create interactive menus under Unix
    ... You will have to use the Korn shell to use a select statement. ... The script looks pretty good but for a few points: ... I would not put a break statement in your catch-all pattern of *. ... echo "Please select a valid entry " ...
    (comp.unix.shell)
  • Re: Strange behavior in Korn shell script
    ... I'm writing a Korn shell script and have encountered a behavior that I ... What I cannot explain is the "grep" statements that are generated. ... change domain to an adult feline. ...
    (comp.unix.shell)