0

I have cross-compiled an executable from c code for an arm-based embedded system. When I execute the binary in the embedded system, it gives the following error:

line 1: syntax error: unexpected word (expecting ")")

I searched around, and figured out it is because the embedded system (some version of Linux) I am using does not have bash but only sh. Is it possible to make my compiled binary executable using sh, without installing bash in it (which is troublesome)?

6
  • Err, if you have a compiled binary, why does sh even parse it? Commented Jul 16, 2020 at 6:25
  • To explicit @JCWasmx86's comment I guess you tried to execute./myprog.c instead of ./myprog_bin Commented Jul 16, 2020 at 6:29
  • Thanks for your prompt reply! I was executing ./myprog_bin instead of ./myprog.c. Even a simple one hello world program has such issue. Commented Jul 16, 2020 at 6:32
  • It could be an error the shell script; it would help if you could add that to your question Commented Jul 16, 2020 at 6:46
  • 1
    @skyuuka : Obviously your binary is not recognized as such. Do a file myprog_bin to find out what the operating system thinks the file is. Commented Jul 16, 2020 at 8:03

1 Answer 1

3

Binaries are not built for the shell program. They are built for a particular architecture and OS environment. All shell does is, fork() a child process and calls exec(). So it won't matter whether your host machine is having bash or sh. Just make sure that binary is for the correct architecture and the machine. And you are indeed executing the binary, not the source.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.