习惯使用sh <script name>的方式来执行脚本, 直到今天创建数组的时候遇到一个错误 Syntax error: "(" unexpected
, 最终找出原因原来是因为sh和bash的不同导致的, 在sh shell中没有创建数组的语法, 所以会报错。
When you use ./scriptname.sh it executes with /bin/bash as in the first line with #!. But when you use sh scriptname.sh it executes sh, not bash.
The sh shell has no syntax to create arrays, but Bash has the syntax you used.
网友评论