On Ubuntu Linux systems can happen to receive unexplained errors when executing bash script. Trying to run the following script, for example:
# / bin / bash #There is no error, but on the systems mentioned above, when you type the following command sh
testall.sh
nets = (0 1 2 3 4 5 6 7 8 9 10 11 12 13 16 17)
jobs = ( 32 25 28 18 10 50 33 12 13 11 11 14 18 14 13 13 )
# get length of array
length = $ {# nets [@]}
# use for loop to read test values \u200b\u200b
for ((i = 0; the <${length}; ++i ));
do
net_ echo $ {nets [$ i]
}. / main {$ jobs [$ i]} {$ net_ nets [$ i]}
echo-e "\\ n" exit 0
done
testall.sh you get this error message testall.sh: 3: Syntax error: "(" unexpected the problem is really very subtle and thus difficult to solve. How
said that at issue is a script bash, / bin / sh is a symbolic link which normally refers to / bin / bash and if so it should work properly. Unfortunately often / bin / sh other hand, refers to the program / bin / dash , and then the syntax is not interpreted correctly and you get an error. To resolve
- just change the symbolic link / bin / sh to point to / bin / bash
- make our script executable and run it as follows
. / Testall .sh in this way, the correct interpreter is automatically selected as the launch of script.
0 comments:
Post a Comment