0

I am writing a bash script in which I am using comm command, I keep getting the error

san.sh: line 12: syntax error near unexpected token `('
san.sh: line 12: `    comm < (grep -r --include "collect.xml" "mean enabled=\"true\"" /opt/Test/test1 | grep -v bak | awk -F/ '{print $7}' | sort -u)  < (cat /etc/bruce/wayne/mansion.ini  | grep LogType | cut -d "=" -f 2 | sort -u)'

comm < (grep -r --include "collect.xml" "mean enabled=&quot;true&quot;" /opt/Test/test1 | grep -v bak | awk -F/ '{print $7}' | sort -u) < (cat /etc/bruce/wayne/mansion.ini | grep Type | cut -d "=" -f 2 | sort -u)

If I where to run the command in the terminal I get the desired output only in the script does it through this error :(

Results after removing spacing issue

  • ok, 1) please don't post images of text, it makes it harder for the readers to copypaste the code to study it, and the code blocks on SE have (at least some sort of) syntax highlighting, which can help find issues. Also esp. that blue on black in your screenshot is quite hard to read, 2) if you have a complex command causing problems, simplify it to remove the unnecessary stuff, e.g. comm <(echo foo) <(echo bar) would be enough here to trigger the syntax error. – ilkkachu Sep 05 '21 at 10:14
  • you're running the script with sh, not bash. From the error message it looks like your sh is Bash, but in sh mode it doesn't support process substitutions, which is why you get the error. Run the scripts with bash, or add the execute permission and run them as ./san.sh so that the hashbang applies.
  • – ilkkachu Sep 05 '21 at 10:16
  • Thank you @ilkkachu My mistake was after correct the spacing issue pointed out by choroba I did not execute the script as bash as you rightly pointed out. After running the script with ./ it worked. I am not sure if I can mark two comments as answer. I do not see an option for it :( – Dorian Gray Sep 05 '21 at 10:34