I'm just trying to run a simple bash script and it's just not working. The entirety of the script is this:
#!/bin/bash
/home/pi/akr2.exe
Just those two lines but when I try to run it:
sh: 1: Syntax error: "(" unexpected
sh: 1: Syntax error: "(" unexpected
There are no parentheses. How is this possible?
Note: I get the same error message whether I run the script with ./script.sh or bash script.sh
I suspect you've compiled akr2.exe on Windows, downloaded it to a Raspberry Pi and try to run it.
Linux on ARM definitely cannot run a binary compiled for Windows on x86.
When Linux tryies to run it, does not find nor the ELF magic numbers for Linux binaries, nor a shebang for a script, at the beginning, so it attempts to run it with /bin/sh. But it's not a shell script, just a binary blob, so sh gives you a syntax error and exits.
Related
This error happens when I run a software containing bash script with beggining like this:
#! /bin/sh
CYBER_UNAME=$(uname)
CYBER_UNAME_M=$(uname -m)
I tried to execute these two commands in terminal and it works fine. This error only happens when I run the shell script. What should I do?
The result of 'uname' is SunOS. This shell script cannot be modified since it's protected on our server.
The line
#! /bin/sh
should read:
#!/bin/bash
So, that script will probably never really work.
If you cannot modify the script in situ, you might want to copy it to your local directory and correct it.
Otherwise,
tail +2 scriptname|/bin/bash
might work.
This is a reduced example of a makefile which illustrates my problem:
exec:
time (ls > ls.txt; echo $$? > code) 2> time.txt
make exec runs fine under one Linux installation:
Linux-2.6.32-642.4.2.el6.x86_64-x86_64-with-centos-6.8-Final
but it fails under my Ubuntu installation:
Linux-4.4.0-64-generic-x86_64-with-Ubuntu-16.04-xenial
and produces the message:
/bin/sh: 1: Syntax error: word unexpected (expecting ")")
No problems if I run the command time directly from the terminal.
Are there different versions of the command in different Linux installations? I need the version which allows a sequence of commands.
Make always invokes /bin/sh to run the recipe. On some systems, /bin/sh is an alias for bash which has a lot of extra extensions to the standard POSIX shell (sh). On other systems (like Ubuntu), /bin/sh is an alias for dash which is a smaller, simpler, closer to plain POSIX shell.
Bash has a built-in time operation which accepts an entire pipeline and shows the time taken for it (run help time at a bash shell command prompt to see documentation). Other shells like dash don't have a built-in time, so when you run it you get the program /usr/bin/time; run man time to see documentation. As a separate program it of course cannot time an entire pipeline (because a pipeline is a feature of the shell); it can only time one individual command.
You have various options:
You can force your makefile to always use bash as its shell by adding:
SHELL := /bin/bash
to it. I recommend adding a comment there as well describing why bash specifically is needed.
Or you can modify your rule to work in a portable way by making the shell invocation explicit so that time only has one command to invoke:
exec:
time /bin/sh -c 'ls > ls.txt; echo $$? > code' 2>/time.txt
Put a semicolon in front of "time". As is, make is trying to parse your command as a list of dependencies.
The only suggestion that worked is to force bash in my makefile:
SHELL := /bin/bash
I checked: on my Ubuntu machine, /bin/sh is really /bin/dash whereas on the CentOS machine it is /bin/bash!
Thanks!
I am not familiar with Linux, just basic commands, I want to use the command below on Ubuntu but I get syntax error.
Command:
curl --progress-bar "http://community.nanocloud.com/nanocloud.sh" | sh
Error:
sh: 2: Syntax error: newline unexpected
You should save the content of the downloaded file first (e.g. using wget instead of curl) and then run sh on the saved file.
wget "http://community.nanocloud.com/nanocloud.sh";
sh nanocloud.sh
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've been closely following commands from 'Linux from scratch' book version 7.2, and as usual everything was fine until i've reached chapter 6.9, and the problem is when I try to install glibc by 'make' command it throws following error at me.
/bin/sh: command substitution: line 3: syntax error near unexpected token `)'
/bin/sh: command substitution: line 3: `/tools/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../i686-pc-linux-gnu/bin/ar t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//')'
make[1]: *** [/sources/glibc-build/linkobj/libc_pic.a] Error 1
make[1]: Leaving directory `/sources/glibc-2.16.0'
make: *** [all] Error 2
So I did some research and surprisingly I wasn't alone with this type of problem but unfortunately I couldn't find good solution (Every thread had a different one). So here are the thing I know so far about this problem.
Bash (4.2.36(1)-release) clearly can't handle brackets especially this type of syntax '$()'
It may have something to do with bash version
other commands which use () don't work as well
And because this is my first time when I went down so deep into linux I honestly have no idea what I'm doing and what to do. So I'd really appreciate your help.
Also i've read somewhere that I can remove all $() from make process but I'm not sure how to do it
I'm using Ubuntu 12.10 to compile LFS and yes I have checked with their script and all dependicies are satisfied. And to help here's env output and simple echo check
TERM=xterm
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin
PWD=/sources/glibc-build
PS1=\u:\w\$
SHLVL=1
HOME=/root
_=/tools/bin/env
OLDPWD=/bin
root:/sources/glibc-build# echo $(test)
bash: command substitution: line 38: syntax error near unexpected token `)'
bash: command substitution: line 38: `test)'
root:/sources/glibc-build# echo $test
test
Source:
http://www.linuxfromscratch.org/lfs/view/stable/index.html
Ok so in order to repair this problem i had to rebuild whole LFS system again but this time with as mentioned above bison and yacc installed on my host machine, so if you experience similar problem to mine just simply execute following command and that should do the trick.
sudo apt-get update && apt-get install bison*