[thelist] shell script issues

Mark Kennedy mark at eurogamer.net
Wed Jan 12 12:40:16 CST 2005


What do you expect

    expr 20265 20292 20314 20342 + 1 - 1

    to do?

There needs to be something between those first 4 arguments, such as a 
plus sign or something.  Type

    expr --help

    in a bash shell to see what expr does.  It *looks* like your code is 
trying to find a process number, and is then using 'expr $PID +1 -1' to 
make sure it's a numeric value.  But you're getting 4 process IDs from 
your 'ps | grep' and so you probably want to split PID up like this 
(bash only):

    for id in $PID
    do
        expr $id + 1 - 1
    done

You will possibly need to set your field separator using

IFS="
"

because I suspect that gawk command will newline delimit the PID list.

Mark


Dan McCullough wrote:
> I keep getting a "expr: syntax error" on this one shell script I am writting.
> basically here is the section that is giving me the problem.
> 
> code:
> PID=`ps -aef | grep Xms128m | grep -v grep | gawk '{print $2}'`
> PID=`expr $PID + 1 - 1`
> output: 
> expr 20265 20292 20314 20342 + 1 - 1
> 
> I need some help in fixing this so it works.  anyone have a suggestion or two?


More information about the thelist mailing list