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
[email protected] :~/package$ su
Password:
[email protected] :/home/zxl/package# dpkg-reconfigure dash
Read More:
- When sh. / xxx.sh is executed, syntax error: “unexpected” appears
- Shell script: syntax error: bad for loop variable error resolution
- The solution of push D command execution error (/ bin / sh: 1: push D: not found) on Ubuntu
- [Fixed] Syntax error: word unexpected (expecting “)”)
- Error when Linux executes sh script: syntax error: bad FD number
- dpkg: error: dpkg frontend is locked by another process
- Syntax error near unexpected token `newline’script cannot be executed
- Solve the problem of syntax error: unexpected end of file or syntax error near unexpected token ` fi ‘error
- Linux view current date and time
- Dpkg: error processing package XXX (- – configure) solution (red warning in the upper right corner of Ubuntu)
- How to Use Apt get Command Under Mac OSX
- Shell script execution error: “syntax error near unexpected token”
- [problem solving] Error:failed to get canonical path of /cow
- git clone https:// gnutls_handshake() failed: The TLS connection was non-properly terminated.
- Syntax error: Bad fd number
- Under the “return-d” mode, the number of “return / return” is 1
- dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
- Solve syntax error: unexpected end of file or /bin/bash^m: bad interpeneter: no match file or directory
- E: sub process / usr / bin / dpkg returned an error code (2) solution under Ubuntu
- Solution of dpkg interrupted problem