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=\"true\"" /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](https://unix.meta.stackexchange.com/questions/4086/psa-please-dont-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
  • 3) 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

1 Answers1

1

The process substitution symbol <( should be written without a space (both of them).

choroba
  • 45,735
  • 7
  • 84
  • 110
  • I did try to remove the space but now it shows as "No such file or directory" `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 Type | cut -d "=" -f 2 | sort -u)` If I just remove – Dorian Gray Sep 04 '21 at 19:11
  • If I just remove a space between two command and not after comm command I get the old error as in description **san.sh: line 12: syntax error near unexpected token `(' san.sh: line 12: ` c** `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 Type | cut -d "=" -f 2 | sort -u)` – Dorian Gray Sep 04 '21 at 19:18
  • The `<(` shouldn't have a space inside. All other spaces were OK. – choroba Sep 04 '21 at 19:27
  • i.e., use `comm <(...) <(...)`. Note that in some cases you also need the redirection operator, in addition to the process substitution, and there you do need a space between the `<`/`>` and the `<(`/`>(`, e.g. `echo foo > >(cat -n)` – ilkkachu Sep 04 '21 at 19:34
  • :( This is the script and it is not working but able to see the results if entered n the terminal `#!/bin/bash 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 Type | cut -d "=" -f 2 | sort -u)` **san.sh: line 12: syntax error near unexpected token (' san.sh: line 12: c 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 Type | cut -d "=" -f 2 | sort -u)** – Dorian Gray Sep 04 '21 at 19:36
  • 1
    A space missing between `)` and `<(`. – choroba Sep 04 '21 at 19:50
  • I am sorry all. I did try all spacing suggestions still keep getting the same error. I was not able to attach a screenshot here so attached it in the description. I tried four different ways of spacing and all had the same result. – Dorian Gray Sep 05 '21 at 09:37
  • Don't use `sh` to run the script. It might run the script in `dash` or whatever else instead of `bash`. – choroba Sep 05 '21 at 17:16