[nflug] Linux & Korn Shell Question
Darin Perusich
Darin.Perusich at cognigencorp.com
Tue Sep 12 11:47:41 EDT 2006
or
user=`who am i |awk '{print $1}'`
term=`who am i |awk '{print $2}'`
it's not a steam lined but it works.
Robert Meyer wrote:
> This is a difficult one. Some versions of shells will run pipes in subshells.
> That means that the variables would get set in the subshell and not in the
> primary shell. Not sure if that's what's happening to you or not. You might
> want to dump the data to a /tmp/ file and issue the read like this:
> read user terminal < /tmp/tmpfile
>
> Just a thought...
>
> Cheers!
>
> Bob
>
> --- Michael James <jamesm at thundertux.org> wrote:
>
>> I'm transferring a script from an IBM AIX box to a Red Hat Enterprise
>> Linux server. One of the first lines in the script determines the
>> logged in user and terminal the script is running under. The syntax is:
>>
>> who am i | awk '{ printf "%s %s\n", $1, $2; } ' | read user terminal
>>
>> The first part give the standard output for the "who am i" command, the
>> first field being the user and the second the terminal. The "awk"
>> command prints just the user and terminal with the idea that the output
>> will be piped into the read command, giving me shell variables for the
>> user and the terminal. This line works fine under AIX and the Korn
>> shell. On Linux, each piece works fine at the CLI, but the entire line
>> doesn't give me any values for the user and terminal variables. I
>> believe the issue is within the pipe. Is there some parameter, switch
>> or something that needs to be different under LInux? The begining of
>> the script is forcing the shell to the korn shell (/bin/ksh) and I've
>> verified that. Any help would be appreciated.
>>
>> Michael R. James
>> jamesm at thundertux.org
>>
>> _______________________________________________
>> nflug mailing list
>> nflug at nflug.org
>> http://www.nflug.org/mailman/listinfo/nflug
>>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> nflug mailing list
> nflug at nflug.org
> http://www.nflug.org/mailman/listinfo/nflug
--
Darin Perusich
Unix Systems Administrator
Cognigen Corporation
395 Youngs Rd.
Williamsville, NY 14221
darinper at cognigencorp.com
_______________________________________________
nflug mailing list
nflug at nflug.org
http://www.nflug.org/mailman/listinfo/nflug
More information about the nflug
mailing list