arithmetic in shell script
Hi,
Though its a simple question, am unable to find answer for this. Expecting the value of "e" as 7. [root@localhost ~]# cat 1.sh a=1 b=2 c=`expr $a + $b` d=4 e=`expr $c + $b` echo $e [root@localhost ~]# sh 1.sh 5 [root@localhost ~]# |
Why would you expect 3 + 2 to equal 7?
|
do not use root for such a simple tests
Code:
# use |
As stated by pan64 and astrogeek, do not use root. Another thing to do is turn on verbose output by adding a "set -xv" line near the top of your script. Also you should add a shebang line at the top of it:
Code:
#!/bin/bash |
Thanks guys.
I learnt new thing to use set -xv from you people from this post. |
Further to examples by pan64, I like to use:
Code:
(( c = a + b )) |
Arun, Did you also learn not to use root for such tasks? Or do you always login as root to avoid any permission problems?
OK |
All times are GMT -5. The time now is 10:41 AM. |