0

I'm still figuring out some niches with bash scripting, I get the following error in my bash script:

updated_names=$(comm -23 <(echo ${current_run_names} | tr " " "\n" | sort) <(echo ${started_run_names} | tr " " "\n" | sort) )
updated_names =$(echo ${updated_names} | cut -d' ' -f1)

Not sure what I've been doing wrong, have deleted various tokens but still continue to get the same error.

How I run it

sh conversion.sh -r directory_location
  • 1
    Are you sure you’re running it with Bash? How do you run the script? – Biffen Jun 18 '21 at 13:14
  • 2
    A [mre] would be helpful, but supposing that the first of the two lines presented is line 72, one possibility would be that Bash is running this in POSIX mode. It would do that if your shebang line were causing Bash to be invoked as `sh` instead of as `bash`. – John Bollinger Jun 18 '21 at 13:16
  • 3
    If your script has a proper shebang you can paste it at https://shellcheck.net for validation, besides what has been mentioned in the above comments. – Jetchisel Jun 18 '21 at 13:23
  • sorry about that, I've posted all of the updated script as can seen above. and how it is run too. Both @biff – Joe_Informatics Jun 18 '21 at 13:25
  • just did again, sorry – Joe_Informatics Jun 18 '21 at 13:28
  • @Joe_Informatics, "how it is run" is indeed part of a MRE, but "all of the updated script" generally is not. Do please help us to help you: present a *minimal* example that demonstrates the problem. – John Bollinger Jun 18 '21 at 13:28
  • 2
    @Joe_Informatics Don’t run it with `sh`. Just run the file and let the shebang do its thing: `./conversion.sh`. – Biffen Jun 18 '21 at 13:28
  • Noticed a difference with by running with bash and not sh – Joe_Informatics Jun 18 '21 at 13:29
  • @Joe_Informatics Next up: Use [ShellCheck](https://www.shellcheck.net). – Biffen Jun 18 '21 at 13:30
  • 1
    Your whole script is not a [mre] -- it may be a reproducible example, but it isn't a **minimal** one. We ask that (and our rules allow enforcement of the requirement that) questions include the _shortest possible_ code that reproduces your bug when run without changes. – Charles Duffy Jun 18 '21 at 13:30
  • CharlesDuffy... I will take into consideration for the future. Did not know about these standards, still fresh to stack overflow obviously... Thanks @Biffen for your help, will use shellcheck in the future :D – Joe_Informatics Jun 18 '21 at 13:35

1 Answers1

1

Supposing that the first of these lines ...

updated_run_names=$(comm -23 <(echo ${current_run_names} | tr " " "\n" | sort) <(echo ${started_run_names} | tr " " "\n" | sort) )
update_run_names=$(echo ${new_run_names} | cut -d' ' -f1)

... is the line 72 referenced in the error message, the issue is most likely with your process substitutions. These are the two fragments of the form <( command ).

Process substitution is a Bash extension to the POSIX shell language. It is not recognized by most other shells, and it is not recognized by Bash itself when it runs in POSIX mode. There is more than one way to get Bash running in POSIX mode, but one of them is to invoke it via the name sh, which is what you are doing.

Note well that the shebang line at the top of your script has a functional role only when you launch the script directly, by making it executable and launching it by name:

./conversion.sh -r directory_location

When you instead launch it as shown in the question, by naming it as an argument to sh, the shebang line is just a comment, and Bash runs (as sh) in POSIX mode.

Note also that although it is conventional for some other language interpreters (Python, especially), it is not conventional to use env in shell script shebang lines.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157