Search code examples
shelldash-shell

Missing "))" in shell script


I'm really sorry I'm a total noob in shell scripting, I looked on the Internet and I didn't find the answer

=> /home/bee/Scripts/chkbsh: 11: /home/bee/Scripts/chkbsh: Syntax error: Missing '))'

#!/bin/sh
for file in $((gawk '/^#!.*( |[/])sh/{printf "%s\0", FILENAME} {nextfile}' /usr/bin/* 2>/dev/null) | xargs -0); do
checkbashisms "$file" >/dev/null 2>&1
if [ "$?" -gt 0 ]
then
    sed -i 's:^#!.*/bin/sh:#!/bin/bash:' "$file";
    echo "$file" has been processed!
fi
done
echo ":3"

If I change #!/bin/sh in #!/bin/bash everything is okay


Solution

  • You have opening double parentheses, but two single closing parentheses. Place a space after the first (, like this:

    for file in $( (gawk '/^#!.*( |[/])sh/{printf "%s\0", FILENAME}
                  ^ there
    

    BTW, it's always good advice to test your scripts with ShellCheck, this way you could have easily spotted above error.