0

I am running a shell script "envsetup.sh" and I keep getting the following error.

Badly placed ()'s

I found out the error is because I am not in a bash shell environment. Can anyone help explain how to enter the bash shell environment?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user2341103
  • 2,333
  • 5
  • 20
  • 19
  • 2
    It'd be extremely helpful if you can post the part of your script that is causing this error. – doubleDown Jul 05 '13 at 22:26
  • 2
    Welcome to Stack Overflow. Please read the [About] page soon. How do you expect us to help you if you don't show us the code that is causing the trouble. Please try debugging with `bash -x envsetup.sh`. Which shell are you using if it isn't `bash`? If you write `echo $SHELL`, it should probably tell you. If you're using `csh`, then you might use `exec bash`, and then type `source envsetup.sh`, and then (maybe) `exec csh` to switch back to `csh`. You may be able to use the `chsh` program to switch your login shell permanently. – Jonathan Leffler Jul 05 '13 at 22:26
  • @JonathanLeffler - I just need to know who to change the shell to bash.. – user2341103 Jul 05 '13 at 22:29
  • 1
    @user2341103 You can't change the shell in the middle of a script without losing all your state. Before we can tell you how to change your shell, we need to know how you got _into_ that shell to start with. Is it the one associated with your OS account? Is it the shell in the shebang (the first line) of a script which, in turn, sourced your `envsetup.sh`? Etc. The additional information is _absolutely necessary_ to be certain that we can provide a correct answer; otherwise, folks are guessing at the details. – Charles Duffy Jul 05 '13 at 23:25
  • Try running `bash -vx envsetup.sh` it will show you each executed subcommand up to the error... Maybe your script is using some bashism and your shell is something else (`dash` perhaps?) – Basile Starynkevitch Jul 05 '13 at 23:39

4 Answers4

5

To switch to a bash login shell (which reads profiles etc), you should type:

exec bash -l

The -l option indicates that it should be a login shell. You can then read the envsetup.sh file using:

source envsetup.sh

You may be able to use the chsh command to change your login shell permanently using a line such as:

chsh /bin/bash

Just make sure the name you specify is the correct path to your copy of bash.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
3

Assuming you are trying to compile Android, you can do the following to temporarily use bash:

$ bash
$ source ./envsetup.sh
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
0x90
  • 39,472
  • 36
  • 165
  • 245
0

Try putting the line:

#!/bin/bash

as the first line of your script. I am assuming the bash command file is in /bin - if not have a look for where it is located and use that path instead.

Arthur Nicoll
  • 391
  • 1
  • 2
  • 8
  • 1
    If the problem is setting up environment (as the name `envsetup.sh` suggests), this probably won't help. – Jonathan Leffler Jul 05 '13 at 22:31
  • It doesn't actually matter whether bash is in /bin. The #!/bin/bash is a convention: it doesn't map it to an actual executable file. – Curt Jul 05 '13 at 22:33
  • 3
    @Curt: It does matter in general, and it does map to an executable file. Try using `#!/no/where/bash` and then try running the script as `envsetup.sh` (or `./envsetup.sh`), and watch for the 'command not found' error. If you source it (`source envsetup.sh` or `. envsetup.sh`), it won't matter, but there are specific reasons for that. – Jonathan Leffler Jul 05 '13 at 22:36
  • Can I go back to your original query and ask if you really want to change to the bash shell? Is the problem not that the syntax of some code in your script is bash specific? Would it be more useful to look at using syntax that works in sh, csh, ksh or whatever shell you are actually in? p.s. You could also use >/bin/bash ./envsetup.sh – Arthur Nicoll Jul 05 '13 at 22:55
  • Another consideration is the use of >. ./envsetup.sh to apply the changes in your script to your current shell. – Arthur Nicoll Jul 05 '13 at 23:00
  • @Curt The shebang line is how the operating system finds the executable interpreter to use to run a script. As such, no, it is not merely convention. – Charles Duffy Jul 05 '13 at 23:27
0

to run a single script envsetup.sh in bash, invoke it like this:

bash envsetup.sh
mnagel
  • 6,729
  • 4
  • 31
  • 66