shell script problem

 Dhénin Jean-Jacques dhenin at gmail.com
Sun Dec 23 15:52:55 UTC 2012


2012/12/23 Polytropon <freebsd at edvax.de>

> On Sun, 23 Dec 2012 10:34:34 +0100, Polytropon wrote:
> > First, the lines with "read" have to be:
> >
> > cat /foo/bar.txt | while read $LINE1
> >
> >       cat /foo/bar/foo/bar.txt | while read $LINE2
> >
> > Reason: $LINE1 and $LINE2 will be evaluated here, they are "empty
> > string", causing "read" to throw an error.
>
> Excuse me - I made a mistake! Of course those two lines
> have to be:
>
> cat /foo/bar.txt | while read LINE1
>
> and
>
>         cat /foo/bar/foo/bar.txt | while read LINE2
>
> The $ infront of the variable names have to be removed.
> The variable _name_, not its content, has to be provided
> to "read" as a parameter.
>
> The script so far:
>
>
>
> #!/bin/sh
>
> cat foo.txt | while read LINE1
>

            *  echo "Pid Process: " $$*


> do
>         cat bar.txt | while read LINE2
>         do
>                 if [ "$LINE1" = "$LINE2" ]; then
>                         sw="1"
>                         echo "Current value of sw is : " $sw
>
                *ps -ax |grep bar *

>                          break
>                 fi
>         done
>         echo "Value of sw is : " $sw
>         if [ "$sw" = "0" ]; then
>                 echo "DO SOMETHING!"
>         fi
>         sw="0"
> done
>



Has you can see,  "pipe" make a subshell and sw is lost.

Hope this help

---------------------------------------------------------
(°>   Dhénin Jean-Jacques
/ )     48, rue de la Justice 78300 Poissy
^^   dhenin at gmail.com
---------------------------------------------------------


More information about the freebsd-questions mailing list