Makefile:
$(shell ./test.sh)
1st experiment: test.sh
echo "hi"
Error I get:
Makefile:1: *** missing separator. Stop.
2nd experiment:
test.sh
echo("hi")
Errors I get:
./test.sh: line 1: syntax error near unexpected token `"hi"'
./test.sh: line 1: `echo("hi")'
Doesn't make any sense...it looks as if 'Make' tries to impose its syntax on the shell script, but the shell script wants its own too.
try ./test.sh.
In the first experiment, the result is
hi
When you run make, the line $(shell ./test.sh) evaluates as hi, which Make doesn't know how to interpret.
In the second experiment,
./test.sh: line 1: syntax error near unexpected token `"hi"'
./test.sh: line 1: `echo("hi")'
You've written a shell script that doesn't have correct shell syntax, so it fails. It fails whether you run it or Make runs it.
Related
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:
the shebang I use is correct and chooses the bash shell , so the process substitution syntax should work
I try the same from the command line and it works. I checked with 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
Remove export POSIXLY_CORRECT=1 from your ~/.bashrc or ~/.profile (etc.) files.
The issue is that process substitution is an added bash feature that is not part of the posix standards.
sh file.sh
errorsh: 3: Syntax error: "(" unexpected
solution:
bash file.sh
I start up my terminal and Bash runs automatically.
When it does I get this error:
-bash: /Users/user/.bash_profile: line 1: unexpected EOF while looking for matching `''
-bash: /Users/user/.bash_profile: line 3: syntax error: unexpected end of file
How do I fix it?
There is an error in /Users/user/.bash_profile involving mismatched quotation marks. Look for mismatched quotes in the first line of that file.
I'm using cygwin. I made a sh file like the following
#!/bin/sh
function bash {
local var="local variable"
echo $var
}
then I execute this file
./test.sh
The result returned is
./test.sh
./test.sh: line 2: syntax error near unexpected token `$'\r''
'/test.sh: line 2: `function bash {
I have no clue how to fix it and use the capability of writing function in bash scripts. Thank you in advance!
Regards,
The error message is trying to tell you there are CRLF line endings, and it doesn't like the CR ($'\r' being a bash way of representing CR, carriage return).
Using Cygwin, you need to do this before executing any bash file:
sed -i 's/\r$//' name_of_your_script.sh
Once done, you can use it normally. If you make any change in the code, use that line again.
This is because there is a problem with the CR when using bash files in Cygwin. This line eliminates those bothering CR and solves the problem.
I have several files under /var/log/uwsgi/ named similar to domain.123456789
I'm trying to loop over the files as given below
for FILE in /var/log/uwsgi/domain.+([[:digit:]]); do
gzip $FILE;
done
this works in console. but when run as a part of a script, i get the following syntax error.
script.sh: line 16: syntax error near unexpected token `('
how can i use substitution in shell scripts?
Make sure that the extglob shell option is enabled in your script by adding:
shopt -s extglob
Without this, the shell won't recognise your +([[:digit:]]) pattern and you will get an error.
You probably already have this set in your bash profile which is why it works in the console.
Can someone explain to me why the following shell script line throws this error:
Syntax error: "(" unexpected
Shell scripts expect variables to be set in the pattern of:
VARIABLE=value
You can't have any additional = signs in there. However, you can execute other scripts like this:
VARIABLE=$(basename $1)
VARIABLE=`basename $1`
Either one works.
In your case, I can't tell what you're doing, but it isn't right at all. My guess is that you need to do this:
env LD_LIBRARY_PATH=$(basename $1)