Syntax error: "(" unexpected (expecting word) --- in my bash script
Solution 1
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.
Solution 2
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'
Related videos on Youtube
Kurama
Updated on September 18, 2022Comments
-
Kurama over 1 year
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. neitherbash
does.-
maulinglawns over 7 yearsIt would be helfpul if you described what you want to achieve.
-
Admin over 7 yearsIt works fine for me.
-
smw over 7 yearsHow 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 -
Stéphane Chazelas over 7 yearsYou're trying to run a bash script with sh. Use
bash my_script.sh
. -
Kurama over 7 years@StéphaneChazelas,
bash -- command not found
andls: /bin/bash: No such file or directory
-
user over 7 years@Kurama What can you tell us about your environment? You tagged this FreeBSD; what can you tell us about the installed version, packages, ...?
-
Stéphane Chazelas over 7 yearsThat syntax is bash syntax (strictly speaking it's more
zsh
syntax as the variables are unquoted). You'll need to either install bash or zsh, or modify it to be in the syntax supported by yoursh
or any other shell available on your system.
-
-
Kurama over 7 years
my_script.sh: command not found
. neither./my_script
is. -
Akhil over 7 yearsWhere 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 installbash
or try to adapt the script so that it runs on your system's shell. -
Akhil over 7 yearsI have added a link in my answer to a tutorial explaining how to install
bash
on FreeBSD. -
Claus Andersen over 7 yearsOn 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
. -
skyuuka almost 4 yearsI 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?
-
Akhil over 3 years@skyuuka I'm a little late to the party, but compiled binary files don't need to be interpretted by the shell to be executed, they are instructions directly executable by your CPU. If you got the program precompiled you should try to compile it again, or follow a tutorial on how to produce an executable from C code (there are many out there). Best of luck !