如何从其他 shell 切换到 bash shell?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17497579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:50:40  来源:igfitidea点击:

How to switch to bash shell from some other shell?

linuxbashunix

提问by user2341103

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

我正在运行一个 shell 脚本“envsetup.sh”,但我不断收到以下错误。

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 bashshell environment?

我发现错误是因为我不在 bash shell 环境中。谁能帮忙解释一下如何进入bashshell环境?

回答by Jonathan Leffler

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

要切换到bash登录 shell(读取配置文件等),您应该输入:

exec bash -l

The -loption indicates that it should be a login shell. You can then read the envsetup.shfile using:

-l选项表明它应该是一个登录shell。然后,您可以envsetup.sh使用以下方法读取文件:

source envsetup.sh

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

您可以使用该chsh命令来永久更改您的登录 shell,例如:

chsh /bin/bash

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

只需确保您指定的名称是您的bash.

回答by 0x90

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

假设您正在尝试编译 Android,您可以执行以下操作来临时使用 bash:

$ bash
$ source ./envsetup.sh

回答by mnagel

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

运行一个脚本envsetup.shbash,调用它是这样的:

bash envsetup.sh

回答by Arthur Nicoll

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.

作为脚本的第一行。我假设 bash 命令文件在 /bin 中 - 如果没有查找它所在的位置并使用该路径。