1

I have a bash script:

#!/bin/bash

VAR1="var1"
VAR2="var2"
VAR3="var3"

cat ${VAR1} \
    <(echo -e '<something>') \                       # <--------- here's the error
    ${VAR2}/file123.txt \
    <(echo -e '</something>\n<something2>') \
    ${VAR3}/file456.txt \
    <(echo -e '</something2>')

When I run it: sh my_script.sh, I get the error:

 my_script.sh: 9: Syntax error: "(" unexpected (expecting word)

update:

bash isn't found, "/bin/bash" doesn't exist. neither bash does.

8
  • 1
    It would be helfpul if you described what you want to achieve. Nov 22 '16 at 11:06
  • It works fine for me.
    – user147505
    Nov 22 '16 at 12:11
  • How are you running the script? The error is characteristic of executing a bash script with a shell that doesn't support process substitutions like <(echo -e '<something>'). See Default Shell Nov 22 '16 at 13:14
  • 1
    You're trying to run a bash script with sh. Use bash my_script.sh. Nov 22 '16 at 13:27
  • 1
    @StéphaneChazelas, bash -- command not found and ls: /bin/bash: No such file or directory
    – Kurama
    Nov 22 '16 at 16:16
3

Try :

chmod 755 "my_script.sh"

Then run it simply like this

my_script.sh

The #!/bin/bash line at the beginning is used to tell your system which shell you should run the script with. I think you are overiding this by executing it with sh my_script.sh. You could also explicitly write /bin/bash my_script.sh. Also if you have some bash specific syntax in your script, you should consider changing the extension to .bash to be more explicit.


EDIT

You don't seem to have bash on your FreeBSD distro (the default shell on FreeBSD appears to be tcsh). You can find here a tutorial to install bash on FreeBSD. The solution I provided should then work properly. Best of luck.

6
  • my_script.sh: command not found. neither ./my_script is.
    – Kurama
    Nov 22 '16 at 16:14
  • Where did you get that script ? It seems that you are trying to run a bash-specific script while not having bash available on your system. You can either try to install bash or try to adapt the script so that it runs on your system's shell. Nov 22 '16 at 16:54
  • I have added a link in my answer to a tutorial explaining how to install bash on FreeBSD. Nov 22 '16 at 17:01
  • On FreeBSD we often recommend to use #!/usr/bin/env bash as the first line in the script. This allows for better cross system portability as bash is not placed in /bin. Nov 24 '16 at 12:33
  • I have a similar issue for a binary file compiled from C code. I cannot install bash as it is an embedded system. Is there anything I can do to make the compiled binary runable in sh?
    – skyuuka
    Jul 16 '20 at 5:54
3

Obviously from the she-bang, that script is intended to be run by bash not sh (even though the syntax looks more like zsh syntax because of the unquoted variables).

You'll want to run it with bash or zsh. If those shells are not available, you can install them or alternatively, translate that script to sh syntax which should be straightforward here.

The sh language (both Bourne or POSIX) has no <(...) operator. That comes from ksh and is supported by bash and zsh as well. echo -e is non-standard and even with bash and ksh only works in some environments.

The standard sh equivalent would be:

var1="var1"
var2="var2"
var3="var3"

cat < "$var1" || exit
printf '<something>\n' || exit
cat < "$var2/file123.txt" || exit
printf '</something>\n<something2>\n' || exit
cat < "$var3//file456.txt" || exit
print '</something2>\n'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.