* [EMAIL PROTECTED]
> 
> IFS=':'
> cat /etc/passwd | while read a b c d
> do
>     if [[ "$a" == "root" ]]
>     then
>        export NAME="$c"
>     fi
> done
> 
> - in ksh this will export NAME into your current env, but not in
> bash. The explanation, I understand, is that when you start a pipeline
> in ksh, the last command in the pipeline (here: where ...) runs in the
> current shell, but in bash all the commands in a pipeline run in a
> subshell.

This does not work in ksh on my RedHat 8.0.  Neither shell do what you
say.


> 
> As I said this is only a minor annoyment, but it does mean that in
> bash you have to use an intermediate file:
> 
> IFS=':'
> cat /etc/passwd > tempfile
> while read a b c d
> do
>     if [[ "$a" == "root" ]]
>     then
>        export NAME="$c"
>     fi
> done < tempfile
> rm tempfile

Ah no.  You do it like this:

 NAME=`IFS=':'
 cat /etc/passwd | while read a b c d; do
  if [[ "$a" == "root" ]]; then
     echo $c
  fi
 done`

-- 
 Jon Haugsand, [EMAIL PROTECTED]
 http://www.norges-bank.no



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to