I want to run this script:
#!/bin/bash
echo <(true)
I run it as:
sh file.sh
And I get "Syntax error: "(" unexpected
" . I found some similar situations but still can't solve this.
I'm a beginner at shell scripting , but as I understand:
echo $0
and it gives me "bash
" , so what's the difference from running the command in the command line and from a script that invokes the same shell?Maybe it's something simple, but I couldn't find an explanation or solution.
You should run your script with bash
, i.e. either bash ./script.sh
or making use of the shebang by ./script.sh
after setting it to executable. Only running it with sh ./script.sh
do I get your error, as commented by Cyrus.
See also: role of shebang at unix.SE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With