[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash script problems

From: Chris F.A. Johnson
Subject: Re: bash script problems
Date: Wed, 11 May 2005 20:43:54 -0400 (EDT)

On Thu, 12 May 2005, Tony Jo wrote:

"Chris F.A. Johnson" <address@hidden> wrote in message
    When quoting parts of a script or error messages, please be
    accurate (cut and paste rather than retyping). You used:

temp=`expr $val1 + $val2`

    or you wouldn't have received that error. The line you have would
    have assigned the literal value to $temp.

Oh those were meant to be single quotes.
temp='expr $val1 + $val2'

    You had single quotes in your post. They should be backticks.

    What are the values of $val1 and $val2? Use this command to see

printf ":%s:%s:\n" "$val1" "$val2"

    What is the result of:

echo $(( $val1 + $val2 ))

    What command did you use to fill those variables?

Those lines didn't seem to print out anything unforunately


    The first command would have printed, at the very least, ":::".

    The second would either have printed a number or an error message.

It prints out values when I simply type the variable name though.
The variable holds the following:
val1='cut -c8-9 usrTime'
val2='cut -c7-8 sysTime'

    If those were the values, then the first command would have

:cut -c8-9 usrTime;cut -c7-8 sysTime:

    What you presumably wanted was for those variables to hold the
    results of the commands, not the commands themselves. For that,
    you enclose the command in backticks, not single quotes:

val1=`cut -c8-9 usrTime`
val2=`cut -c7-8 sysTime`


val1=$(cut -c8-9 usrTime)
val2=$(cut -c7-8 sysTime)

    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress

reply via email to

[Prev in Thread] Current Thread [Next in Thread]