jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at <builtin>, line 1: - jq

I'm having trouble running jq from my linux host. I don't understand why.
$ uname -a
Linux localhost.localdomain 5.3.8-200.fc30.x86_64 #1 SMP Tue Oct 29 14:46:22 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
モ cat /etc/redhat-release
Fedora release 30 (Thirty)
$ echo $SHELL
/bin/bash
$ file $(which jq)
/usr/bin/jq: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=aca83aa7ecf04e5385c4cc94657cfc9ea1df86d3, stripped
$ jq --version
jq-1.6
$ echo '{}' | jq .
jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at <builtin>, line 1:
ELF
jq: 1 compile error

This happened to me when I tried to use a .jq file with CR/LF line endings on Linux. Changing it to LF fixed the problem.

Related

Symlink make as gmake on Mac

I am running a program (OpenModelica OMEdit 1.18.0~dev-109-ged8ef0a) which requires gmake for one of its operations. gmake is not installed on my Mac (Big Sur 11.5.2) but make is. I tried to symlink gmake to point at make but it does not work:
➜ where make
/usr/bin/make
➜ make -v | HEAD -n 1
GNU Make 3.81
➜ pwd
/opt/openmodelica/bin
➜ sudo ln -s /usr/bin/make /opt/openmodelica/bin/gmake
➜ ls -lh gmake
lrwxr-xr-x 1 root wheel 13B 13 Dec 09:15 gmake -> /usr/bin/make
➜ /opt/openmodelica/bin/gmake -v
gmake: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find gmake 2> /dev/null' failed with exit code 17664: (null) (errno=Invalid argument)
xcode-select: Failed to locate 'gmake', requesting installation of command line developer tools.
It prompts each time to install the XCode command line developer tools which I have already done. From the error message it looks like it is trying to find gmake despite pointing at the make executable? (Why is it erroring?) Is there a way to get this to work as I was expecting or do I have to install gmake using brew then symlink to that?
Command line tools version:
➜ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 12.5.1.0.1.1623191612
volume: /
location: /
install-time: 1639360537
groups: com.apple.FindSystemFiles.pkg-group
** edit **
I'm using zsh 5.8 (x86_64-apple-darwin20.0), I don't know if that's a factor in the gmake symlink to make not working correctly?
I don't understand why this works but from #Holger Just's comment:
➜ brew install make
This will add a symlink:
➜ ls -lh /usr/local/bin/gmake
/usr/local/bin/gmake# -> ../Cellar/make/4.3/bin/gmake
And then symlinking to that instead:
➜ sudo ln -s /usr/local/bin/gmake /opt/openmodelica/bin/gmake
... works as expected:
➜ /opt/openmodelica/bin/gmake -v | head -n 1
GNU Make 4.3

Debian Packaging Without Build Tool

I want to create a Debian package from a C program without the use of a build tool such as autotools or CMake. My debian/rules file:
#!/usr/bin/make -f
%:
dh $#
override_dh_auto_clean:
rm -f program
override_dh_auto_build:
gcc program.c -o program
override_dh_auto_install:
cp program /usr/local/bin
Upon running dpkg-buildpackage, I get:
dh: error: Unknown sequence application (choose from: binary binary-arch binary-indep build build-arch build-indep clean install install-arch install-indep)
It seems the issue was related to the fact that I was creating the file in a shell script heredoc that was expanding the $#, e.g.
cat <<EOF > debian/rules.temp
#!/usr/bin/make -f
%:
dh $#
EOF
Which should be:
all_symbol='$#'
cat <<EOF > debian/rules.temp
#!/usr/bin/make -f
%:
dh $all_symbol
EOF
An unrelated issue is to the location of the override_dh_auto_install To manually create Debian file hierarchy it should be:
override_dh_auto_install:
mkdir -p debian/PACKAGENAME/usr/bin
cp program debian/PACKAGENAME/usr/bin
Or, to have this done automatically:
cat <<EOF > debian/PACKAGENAME.install
program usr/bin
EOF

How to prevent R system command syntax error

I am trying to run a command similar to
> system("cat <(echo $PATH)")
which fails when run from within R or Rstudio with the following error message:
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `cat <(echo $PATH)'
However, if I run this on the command line it works fine:
$ cat <(echo $PATH)
[...]/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
I checked that the shell I am using is bash using system("echo $SHELL"). Can anyone help me solving this?
This syntax works in bash but not sh. The $SHELL environment variable doesn't necessarily mean that is the shell being used. echo $0 will show your shell.
system("echo $0")
#> sh
You could force bash to be used like this
system("bash -c 'cat <(echo $PATH)'")
#> /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

How does zsh interpret non-absolute paths in shebangs? (WAS: Why does python3 -i permit non-absolute paths in shebang?)

I recently discovered the -i argument to Python, which drops into interactive mode after the script completes. Pretty neat!
$ cat test.py
#!python3 -i
x=5
print('The value of x is ' + str(x))
$ ./test.py
The value of x is 5
>>> print(str(x+1))
6
>>>
zsh: suspended ./test.py
However, when I tried to copy this script to a version that terminates on completion, it fails:
$ cat test1.py
#!python3
x=5
print('The value of x is ' + str(x))
$ ./test.py
/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python: can't open file '
x=5
print('The value of x is ' + str(x))
': [Errno 2] No such file or directory
From some further reading, I discovered that I had originally made a mistake, and #!/usr/bin/env python3 is the correct shebang.
However, I'm curious why a non-absolute path to python3 succeeds only when I give the -i flag. I guess this must be something to do with how zsh interprets non-absolute shebangs, but I don't know enough to know how to investigate that.
System setup: MacOS 10.12.6, iTerm2 3.1.6, zsh 5.2. which python3 gives /usr/local/bin/python3, and that directory is on $PATH.
Interestingly, I don't get the same behaviour on sh:
$ sh
sh-3.2$ cat test.py
#!python3
x=5
print('The value of x is ' + str(x))
sh-3.2$ ./test.py
sh: ./test.py: python3: bad interpreter: No such file or directory
I got some comments suggesting that this is something to do with CWD or permissions. python3 is not in my CWD, and both files have execute permission:
$ ls -al | grep 'py' | awk '{print $1, $10}'
-rw------- .python_history
-rwxr-xr-x test.py
-rwxr-xr-x test1.py
Your kernel will not execute the script unless the interpreter is
specified as an absolute path, or
specified as a path relative to the current working directory
Then if the kernel refuses to execute the script, your shell might take over and try to execute it anyway, interpreting the shebang line according to its own rules (like finding the executable in the $PATH for example).
zsh does attempt to do this. sh does not.
However the way zsh interprets the shebang (and probably subsequent lines) is really really strange. It looks like it always expects a single argument after the command name. See what it does:
$ cat test.py
#!python3 -b -i
x=5
print('The value of x is ' + str(x))
$ strace -f -e execve zsh
execve("/bin/zsh", ["zsh"], 0x7ffd35c9e198 /* 78 vars */) = 0
host% ./test.py
strace: Process 5510 attached
[pid 5510] execve("./test.py", ["./test.py"], 0x558ec6e46710 /* 79 vars */) = -1 ENOENT (No such file or directory)
[pid 5510] execve("/usr/bin/python3", ["python3", "-b -i", "./test.py"], 0x558ec6e46710 /* 79 vars */) = 0
[pid 5510] execve("/usr/lib/python-exec/python3.4/python3", ["/usr/lib/python-exec/python3.4/p"..., "-b -i", "./test.py"], 0x7fffd30eb208 /* 79 vars */) = 0
Unknown option: -
usage: /usr/lib/python-exec/python3.4/python3 [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
[pid 5510] +++ exited with 2 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=5510, si_uid=1000, si_status=2, si_utime=0, si_stime=0} ---
host%
+++ exited with 2 +++
See how ["python3", "-b -i", "./test.py"] are passed as arguments. It seems highly counterintuitive to me to lump the two switches -b and -i together, but that's what zsh does. Python obviously doesn't understand this.
When there are no arguments, the exact behaviour depends on whether there is a space after the program name, but is strange in either case. Check it with strace yourself because you are not going to believe me.
It is my understanding that zsh handling of the shebang line is just buggy.

nohup not working in following unix following version

I have a script script.sh and need to give 2 inputs: f1.txt and f2.txt.
When I run nohup ./script.sh f1.txt f2.txt & it gives error like follows
./script.sh: print: not found
./script.sh: print: not found
./script.sh: VPATH=:/: is not an identifier
But when I run ./script.sh f1.txt f2.txt or ./script.sh f1.txt f2.txt &
it's working fine.
Not working with nohup script.sh f1.txt f2.txt
Unix Version
Solaris 8 2/02 s28s_u7wos_08a SPARC
Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
Assembled 18 December 2001

Resources