Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

执行提示语法错误 13行 Syntax error: "(" unexpected #75

Closed
niuniu9631 opened this issue Jul 31, 2018 · 5 comments
Closed

执行提示语法错误 13行 Syntax error: "(" unexpected #75

niuniu9631 opened this issue Jul 31, 2018 · 5 comments

Comments

@niuniu9631
Copy link

niuniu9631 commented Jul 31, 2018

show-busy-java-threads.sh

本地环境测试都是可以使用的,放到线上去就提示错误,烦请大神指点

test.sh: 13: test.sh: Syntax error: "(" unexpected
@oldratlee
Copy link
Owner

oldratlee commented Jul 31, 2018

给一下 你的运行方式。 @niuniu9631

更多 排查 和 报问题要提供的信息 参见

@niuniu9631
Copy link
Author

niuniu9631 commented Jul 31, 2018

这一行提示的错误

readonly -a COMMAND_LINE=("$0" "$@")

运行方式:

# 进入所在目录后, 执行
sh test.sh

线上用的是阿里云ECS服务器

@niuniu9631
Copy link
Author

多谢。

@oldratlee
Copy link
Owner

oldratlee commented Aug 1, 2018

#57 (comment)

尽量不要自己去指定sh的方式去执行脚本 @wanghaile (这个是坏习惯 😄 ) :

  1. 脚本已经是可执行模式的,在里面指定的是bash,操作更简单些。
    脚本中总是声明上确定的shell(如bash)是好的实践: #!/bin/bash
  2. 不同的shell(sh、bash、zsh、fish、csh、tcsh、ksh、ash、dash……)有各种差异,深坑勿入。
    目前主流的是bash/zsh
    更多shell的信息 参见 https://en.wikipedia.org/wiki/Comparison_of_command_shells
  3. sh可能是个符号链接,可能链接到不同的shell,如有的Ubuntu版本,sh是链接到dash的。

简单地说,用sh运行是个深坑,勿入!
# 原因见上面的说明。 @niuniu9631

推荐直接执行的方式:

wget https://github.com/oldratlee/useful-scripts/raw/master/show-busy-java-threads
chmod +x show-busy-java-threads
./show-busy-java-threads

@niuniu9631
Copy link
Author

恩,采用大神推荐的方式执行成功了,太感谢了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants