At 03:32 PM 5/21/98 +0100, Philip Hazel wrote:
>On Thu, 21 May 1998, Bruce Bowler wrote:
>
>> a=`ls -lg $mainlog`
>> b=`ls -l $mainlog`
>> user=`echo "$a\n$b\n" | awk 'BEGIN { OFS=""} { if ($5 ~ /^[0-9]+$/) print
>> $3; }'`
>> group=`echo "$a\n$b\n" | awk 'BEGIN { OFS=""} { if ($5 ~ /^[0-9]+$/) print
>> $4; )'`
>>
>> On my system, that results in
>>
>> user=root\nroot
>> group=bin\nbin
>
>Hmm. I'm guilty of assuming that everybody's /bin/sh is the same, I
>suspect. I naively thought that *every* Unix system had the same
>/bin/sh, namely the Bourne Shell. Sigh. I see that the command
>
>echo "a\nb"
>
>behaves differently in /bin/bash and /bin/sh or /bin/ksh. I surmise that
>your /bin/sh is really /bin/bash.
As far as I know (and I installed the system and am the only one I know of
with root access) my /bin/sh is, in fact, /bin/sh. bash doesn't exist on
this system.
>By experiment,
>
>user=`echo "$a
>$b
>" | awk 'BEGIN { OFS=""} { if ($5 ~ /^[0-9]+$/) print $3; }'`
>group=`echo "$a
>$b
>" | awk 'BEGIN { OFS=""} { if ($5 ~ /^[0-9]+$/) print $4; )'`
>
>works in both /bin/sh and /bin/bash. I will change the script.
That does not behave any differently on my system.
ls -l and ls -lg both return identical results on my system. So what you
are in effect doing is awking a file that looks like
-rwxr-xr-x 1 root bin 261 May 21 11:02 mainlog
-rwxr-xr-x 1 root bin 261 May 21 11:02 mainlog
awk performs the BEGIN action once, to set the output field seperator, then
for each record in the file (and there are 2), it says if field 5 is
numeric, print field 3 so awk produces, on stdout
root
root
I'm not an awk programmer so I can't suggest a "simple" fix, but my
brute-force method would be to change ORS to a space, then run the
resulting output through awk again, with a simple print $1, something like
user=`echo "$a\n$b" | awk 'BEGIN { ORS=" "} { if ($5 ~ /^[0-9]+$/) print
$3; }'| awk '{print $1}'`
which, while not pretty, does appear to work on my system.
Bruce Bowler, Research Associate 207.633.9600 (voice)
Bigelow Laboratory for Ocean Sciences 207.633.9641 (fax)
PO Box 475 BBowler@??? (email)
West Boothbay Harbor ME 04575 http://www.bigelow.org/
--
*** Exim information can be found at
http://www.exim.org/ ***