I've searched the forum and google, but can't see an answer to this simple problem. Here's my small test script:
#!/bin/csh
echo "enter a number:"
read num
echo "you entered $num"
set num = `expr $num + 1`
echo new value is $num
can someone show me how to do this calculation? note that in the real life script I'm working on, variables will be input, so something like
set num = 1
won't work for me
here's an example of the execution
Thanks in advance for your time and help.
Tom
tpatput,
Is this what you need:
num=$num+1
thank you for your response shell_life.
I modified the test script to this and it worked under sh shell
#!/bin/sh
echo "enter a number:"
read num
echo "you entered $num"
num=`expr $num + 1`
echo the result is $num
execution:
I couldn't run just num=$num+1. Maybe I'm getting screwed up with the login shell and the script shell.
is there a way to do this in csh (or tcsh)?
Thanks again for your help.
Tom
anbu23
4
#/bin/csh
echo -n "enter a number:"
set num = $<
echo "you entered $num"
set num = `expr $num + 1`
echo the result is $num
anbu23, shell_life, thanks so much for your quick responses. You've really helped and it is very much appreciated.
Tom