问题---执行sh ./xxx.sh出现:Syntax error: "(" unexpected (expecting "done")

 

 这与实际使用的shell版本有关。
可以用 ls -l /bin/*sh 打印出来,例如:

问题---执行sh ./xxx.sh出现:Syntax error: "(" unexpected (expecting "done")

 

 在这里,sh被重定向到dash,因此,如果执行./example.sh,则使用的是dash 。
避免报错可有多种方法,例如执行: bash example.sh ;
或者将脚本第一行#!/bin/sh 改为:#!/bin/bash ,执行./example.sh也可以。

 

另一种解决办法:

代码对于标准bash而言没有错,因为Ubuntu/Debian为了加快开机速度,用dash代替了传统的bash,是dash在捣鬼,解决方法就是取消dash:
sudo dpkg-reconfigure dash ,在选择项中选No。

@https://blog.csdn.net/u014470581/article/details/51493150

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-10-20
  • 2022-12-23
猜你喜欢
  • 2021-06-14
  • 2021-06-10
  • 2022-01-14
  • 2022-12-23
  • 2021-08-27
  • 2021-09-20
  • 2022-12-23
相关资源
相似解决方案