I wanted to determine the version of the Intel Fortran compiler in my makefile, so I added some script using GNU shell function as below for testing,
VERIFORT := $(shell ifort --version)
#VERIFORT := $(shell ifort --version | grep ^ifort) # error occurred too
.PHONY: test
test:
echo $(VERIFORT)
If you copy those code lines shown above, make sure there is a tab before the echo command.
which gives me some errors
/bin/sh: -c: line 0: syntax error near unexpected token `('
When I ran the command ifort --version or ifort --version | grep ^ifort in a terminal, it gave proper result and no error occurred.
My system: 64-bit CentOS 7
Appreciate any correction suggestions.
[EDIT]
Add more output details:
With the grep version of VERIFORT, the make command produced the following result,
echo ifort (IFORT) 18.0.2 20180210
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `echo ifort (IFORT) 18.0.2 20180210'
make: *** [test] Error 1
[SOLVED]
It turns out to be an echo-usage problem as mentioned by #MadScientist
I think you need to quote the value of the VERIFORT variable when you print it, so that the shell doesn't interpret special characters.
Quoting the VERIFORT variable produced the following result (the grep version)
echo 'ifort (IFORT) 18.0.2 20180210'
ifort (IFORT) 18.0.2 20180210
and no error occurred.
I also tested it by using echo in a terminal
echo ifort (IFORT) 18.0.2 20180210
Which generated the same error
bash: syntax error near unexpected token `('
It seems you didn't show the complete output of the make command. I think before this error message, make printed an echo line (unless the makefile you showed us isn't actually what you invoked, and your actual makefile adds a # before the echo... in which case you should remove it while you debug). If you'd shown us what that output was it would be more clear what the problem is. Also you didn't show what the output of the ifort --version command is when you run it from the command line, but I think it probably contains parentheses.
I think you need to quote the value of the VERIFORT variable when you print it, so that the shell doesn't interpret any special characters:
test:
echo '$(VERIFORT)'
Related
I want to compute the time it takes to finish my command in makefile.
Here is what I tried, but it doesn't work:
FILE = some_file.6.txt
.ONESHELL:
another_file.txt: ${FILE}
#START=$$(date +%s.%N)
#END=$$(date +%s.%N)
#echo $$(($$END-$$START))
Here is the error I get:
$ make
/bin/sh: 3: arithmetic expression: expecting EOF: "1569658240.437512688-1569658240.436685866"
makefile:5: recipe for target 'another_file.txt' failed
make: *** [another_file.txt] Error 2
I've tried all combination of adding/removing both ( and $.
Please help, thanks.
This is not a makefile problem. It's a shell problem. This is trivially seen by running the command at a shell prompt rather than a makefile, and you'll get the same error:
$ /bin/sh -c 'echo $((1569658240.437512688-1569658240.436685866))'
/bin/sh: 1: arithmetic expression: expecting EOF: "1569658240.437512688-1569658240.436685866"
It's also an error in bash, so setting SHELL := /bin/bash won't help:
$ /bin/bash -c 'echo $((1569658240.437512688-1569658240.436685866))'
/bin/bash: 1569658240.437512688-1569658240.436685866: syntax error: invalid arithmetic operator (error token is ".437512688-1569658240.436685866")
If you check the documentation for your shell you'll see that arithmetic expressions only work on integer values, not floating point values as you're attempting above.
To perform more advanced math including on floating point values, you should investigate the bc program:
.ONESHELL:
another_file.txt: ${FILE}
#START=$$(date +%s.%N)
#END=$$(date +%s.%N)
#echo $$END-$$START | bc
So, Im working with a Ruby script that needs to connect to a bunch of servers and get information from them. The problem I am having is that the single quotes seem to be getting lost somehow. What am I doing wrong here ?
command = "grep -E \'^(upstream| *server)\' /etc/nginx/upstreams.conf | sed -E \'s/_pool.*//g ; s/^upstream //g\'"
puts system("ssh -n -o 'StrictHostKeyChecking no' #{nginx_stage_servers[0]} #{command}")
Error I am getting :
$ ruby nx.rb
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `grep -E ^(upstream| *server) /etc/nginx/upstreams.conf'
true
The reason of the error is the single quotes missing.
You have too many layers of quoting and escaping to deal with when you use system(command_string), you're almost always better off using the multi-argument form of Kernel#system to avoid dealing with the shell. Something like this will be less problematic:
system('ssh', '-n', '-o', 'StrictHostKeyChecking no', nginx_stage_servers[0], command)
From the docs:
.ONESHELL
If .ONESHELL is mentioned as a target, then when a target is
built all lines of the recipe will be given to a single invocation
of the shell rather than each line being invoked separately (*note
Recipe Execution: Execution.).
So, a makefile, like:
.ONESHELL :
all ::
echo 'foo
bar'
Running, I get:
$ make
echo 'foo
/bin/sh: 1: Syntax error: Unterminated quoted string
makefile:4: recipe for target 'all' failed
make: [all] Error 2 (ignored)
Trying, with almost the same makefile, but adding a - prefix to the recipe, to ignore errors, as documented:
To ignore errors in a recipe line, write a '-' at the beginning of
the line's text (after the initial tab). The '-' is discarded before
the line is passed to the shell for execution.
The makefile, like:
.ONESHELL :
all ::
-echo 'foo
bar'
Running, I get:
$ make
echo 'foo
/bin/sh: 1: Syntax error: Unterminated quoted string
makefile:4: recipe for target 'all' failed
make: [all] Error 2 (ignored)
bar'
/bin/sh: 1: Syntax error: Unterminated quoted string
makefile:4: recipe for target 'all' failed
make: [all] Error 2 (ignored)
Why?
GNU Make 3.81 does not support .ONESHELL, but 3.82 does.
$ /usr/gnu/bin/make --version
GNU Make 3.82
$ /usr/bin/gmake --version
GNU Make 3.81
$ cat gnu.mk
.ONESHELL:
all:
echo 'foo' "$$$$"
echo 'bar' "$$$$"
$ /usr/bin/gmake -f gnu.mk
echo 'foo' "$$"
foo 3100
echo 'bar' "$$"
bar 3101
$ /usr/gnu/bin/make -f gnu.mk
echo 'foo' "$$"
echo 'bar' "$$"
foo 3103
bar 3103
$
I deduce that you're using GNU Make 3.81 from 2006 (or possibly an earlier version, but 3.80 is from 2002); 3.82 is from 2010. The current version is 4.1 from 2014. The online documentation applies to the current version. While lots of the material also applies to older versions, not all of it does.
I also observe that the original makefile with the single single quote on the first line and another on the second seems to cause trouble even with GNU Make 3.82. However, when the lines are each OK, it does seem to work. That's a bit puzzling. And, now I've also installed GNU Make 4.1 (I'd already got it downloaded, but hadn't built it), it too has problems with the bust.mk file below.
$ cat bust.mk
.ONESHELL:
all:
echo 'foo
bar' "$$$$"
$ /usr/gnu/bin/make -f bust.mk
echo 'foo
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [all] Error 2
$
I'm not sure I understand how GNU Make gets confused by that. It might be worth filing a bug for it. OTOH, I'm not sure I'm going to get worried about it, either. But you'll need to take this odd behaviour into account in your future testing.
In a Makefile, I need to cycle through a list and write the current element of the list in a file.
The code is the following:
SHELL := /bin/bash
LIST = A B C
test:
for i in $(LIST) do \
echo $ii > file.txt \
done
I get the following error:
/bin/bash: -c: line 1: syntax error near unexpected token `>'
Do you know how to fix it?
You are missing a ; after $(LIST). You need to terminate the list of words you are giving to for before you can start the do block.
As indicated in the comments, you additionally need a : at the end of the echo line (the command that gets run has no newlines the way this works at the normal command line so you need to explicitly separate the commands from each other).
And further, to get the results you expect, you need to escape the $ in the shell command by using $$i (also pick one of $i or $ii as your variable name).
I wrote a conder script for a job and use condor_submit to submit this job. Below is my script:
Executable=/bin/bash
Arguments=" -c "" command_to_run -d -f"" "
initialdir= /path/
output=/path/out
error=/path/err
log=/path/log
universe = vanilla
Getenv = true
Queue
As seen above, the executable is bash and I use -c to pass the command as a string to bash. The job gets submitted fine, but I get the following error message in err output file:
command_to_run: -c: line 0: unexpected EOF while looking for matching `"'
command_to_run: -c: line 1: syntax error: unexpected end of file
This is simply bash complaining about unmatched double quotes. But double quotes look fine to me. I don't know what the problem is. It seems like it is a condor problem. Any ideas?
If you're just passing -c to bash then single quoting should be sufficient (unless you're trying to embed variables):
Arguments=" -c 'command_to_run -d -f' "