Shell脚本中自定义变量报错 command not found
Shell中自定义变量 报错: command not found
以前都没能接触到编写shell脚本,今天尝试用shell完成简单的加法操作,却出现报错,具体内容如下:
$cat add.sh
#!/bin/bash
a = $1
b = $2
(( c = $a + $b ))
echo "$a + $b = $c"
[hadoop@node100 XiaoF]$ sh add.sh 1 3
add.sh: line 3: a: command not found
add.sh: line 4: b: command not found
add.sh: line 5: ((: c = + :
syntax error: operand expected (error token is "+ ")
+ =
后来发现报错的原因是在于“=”左右两边我加上了空格,将“=”两边的空格去掉就可以了
[hadoop@node100 XiaoF]$ vim add.sh
[hadoop@node100 XiaoF]$ cat add.sh
#!/bin/bash
a=$1
b=$2
(( c=$a+$b ))
echo "$a+$b=$c"
[hadoop@node100 XiaoF]$ sh add.sh 34 55
34+55=89
还没有评论,来说两句吧...