1

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

Aserre
  • 4,916
  • 5
  • 33
  • 56
inanmb
  • 15
  • 2

2 Answers2

2

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.

rkta
  • 3,959
  • 7
  • 25
  • 37
-2

Try

for file in `gawk '/^#!.*( |[/])sh/{printf "%s\0", FILENAME} {nextfile}' /usr/bin/* 2>/dev/null | xargs -0`; do
checkbashisms "$file" >/dev/null 2>&1
  • 2
    Using a deprecated syntax isn't a good workaround for this kind of issue – Aserre Mar 02 '18 at 10:47
  • Thanks for the thanks, setting as accepted answer would be appreciated. The syntax is correct and POSIX compatible and more legible as the execution command contains parenthesis, that's why I proposed the back-tic which is not formally deprecated. In this case, the style is better. – Jose Manuel Gomez Alvarez Mar 11 '18 at 17:25