Question:
The SH script contains the contents of array initialization
$ str="123 456 789" $ array=($str) $ echo ${array[2]}
SH executing the script will report an error Syntax error: "(" unexpected
reason:
Other common Linux distributions, although many point sh to bash
The SH command on Debian/Ubuntu points to dash instead of bash by default
And because dash is lighter than bash, it only supports basic shell functions,
It does not include the array initialization just now, so it can not be recognized. Syntx error is directly reported
solve:
The solution is to use it directly bash test. Sh
, or ./test. Sh
, these two ways to execute the script.
When executing sh./xxx.sh, the solution of “syntax error:” (“unexpected”) appears
Yesterday, the system identification part of virtualmin was updated to enable it to support one click installation and optimization under Debian system. The code was almost modified. Reinstall the VPS into Debian. Execute the code through sh./virtualmin.sh and report “syntax error:” (“unexpected”) Error. It’s OK to execute through bash./virtualmin.sh. After searching the syntax for several times, there’s no problem. Later, find the cause of the problem on the Internet:
The code is correct for standard bash, because Ubuntu/Debian uses dash instead of traditional bash in order to speed up startup. Dash is making trouble. The solution is to cancel dash.
solve:
1) sudo dpkg-reconfigure dash Select no from the options and it’s done!
2) Execute dpkg reconfigure dash under root and select No
zxl@ubuntu :~/package$ su
Password:
root@ubuntu :/home/zxl/package# dpkg-reconfigure dash
Read More:
- Error when Linux executes sh script: syntax error: bad FD number
- When sh. / xxx.sh is executed, syntax error: “unexpected” appears
- SH script reports error “Eval: Line 1: syntax error: terminated quoted string”
- Vue executes NPM run Dev and reports an error: missing script: dev
- The python script tool of ArcGIS reports an error: indentationerror: unexpected indent solution
- Vue project reports an error on ie11 white screen. Script1002: syntax error
- Syntax error near unexpected token `newline’script cannot be executed
- Shell script syntax error near unexpected token ‘$’Do
- Solve the problem of shell script “syntax error near unexpected token `fi’”.
- Shell script execution error: “syntax error near unexpected token”
- Solve the problem of syntax error: unexpected end of file or syntax error near unexpected token ` fi ‘error
- PHP reports “parse error: syntax error, unexpected T”_ The solution of “variable”
- Repo reports an error syntax error: invalid syntax
- The remote port occupation of Linux startup jar package script reports an error
- Shell script: syntax error: bad for loop variable error resolution
- When Linux installs redis, it executes make install and reports an error: Make: * * [server. O] error 1 (solved)
- [development experience] solution to unexpected syntax error: unexpected identifier in JSON parsing
- ubuntu executes apt-get update and reports Failed to fetch/replace Ali source
- “Unexpected syntax error: unexpected identifier”.
- [Fixed] Syntax error: word unexpected (expecting “)”)