- Bourne shell (sh) - C shell (csh) - TC shell (tcsh) - Korn shell (ksh) - Bourne Again shell (bash)
问题:
- 当我打开一个终端窗口时,默认打开哪个壳? - 如何检查已安装了多少个壳? - 如何更改我账户使用的壳?
echo $0
-bash
0
是一个环境变量吗? - Mi_Onimcsh
是不起作用的。% echo $0 No file for $0.
,但对于 tcsh
是起作用的。 - Sergiy Kolodyazhnyybash
作为sh
使用。 - Anwarcsh
?还是这是设计上的限制? - asgsecho $0
中获取shell名称后,执行ls -l `which <name>`
来查看它是否链接到另一个shell二进制文件。 - JivanAmarasu - user
上工作。 - Luis Muñizmyfunc
的shell函数中访问时,$0
对于bash来说是bash
,而对于zsh来说是myfunc
。 - frozen-flameecho $SHELL
或检查进程ID。 - Mike Bsource
命令时不适用于zsh
。为了确认这一点,请尝试创建名为foo.sh
的文件,其中包含以下内容:echo $0
,然后创建名为main.sh
的文件,其中包含以下内容:echo $0 && source ./foo.sh
。执行zsh main.sh
的输出应为zsh.sh\n./foo.sh
,这就是我说$0
在zsh
中无效的原因。 - doltesSHELL
环境变量的值。echo $SHELL
echo "$$"
ps -p <PID>
ps -p "$$"
echo $SHELL
з»ҷеҮәдәҶ /bin/csh
пјҢиҖҢ ps -p $$
з»ҷеҮәдәҶ 22673 pts/1 00:00:00 bash
гҖӮKingmiloеңЁдёҠйқўи§ЈйҮҠдәҶе®ғ们дёҚеҗҢзҡ„еҺҹеӣ гҖӮ - 18446744073709551615ps -cp "$$" -o command=""
。 - James Tomasinokill $(echo "$$")
,但我的shell仍在运行。 - theXfish: $$ is not the pid. In fish, please use %self.
不过至少那时,我知道我正在使用fish shell,而不是bash,因为 echo $SHELL
会让我相信这一点。 - hlongmoreps -cp "$$" -o command=""
作为一个shell命令时,我得到的输出是ps
而不是它所使用的shell。 - Miguel Guthridge$SHELL
给出默认的 shell。
$0
给出当前的 shell。
例如:我默认使用 bash 作为我的 shell,用于终端应用程序。但对于 iTerm2 应用程序,我在打开窗口时使用命令:/bin/ksh
。
所以我的
$0
在 iTerm2 上给我 /bin/ksh
。
$SHELL
在 iTerm2 上给我 /bin/bash
。
$0
、$SHELL
在 Terminal 上给我 /bin/bash
bash
。要切换回zsh,只需输入zsh
即可。 - Yousuf Azadzsh
,但要切换到bash
,我只需输入bash
,要返回到原来的shell,只需输入exit
或按下ctrl + D即可。 - Sanjaysh -c 'ps -p $$ -o ppid=' | xargs ps -o comm= -p
sh -c 'ps -p $$ -o ppid=' | xargs -I'{}' readlink -f '/proc/{}/exe'
ppid=
/cmd=
来省略标题(以及tail -1
),并考虑查看/proc/.../exe
,以查看正在运行的文件(因为cmd
输出可能会被运行shell的程序操纵)。 - muruBusyBox
这样不支持ps
命令的shell中运行,并且也没有像cut
这样的其他实用工具来帮助。代码:set -- $(ps -o pid,ppid | grep -E "^ *$$"); readlink -f "/proc/${2}/exe"
。我正在使用你的方法来确定一堆“免费在线Linux shell”网站上使用的shell,效果非常好! - Seanfish
和csh
这样的奇怪的shell,并且仍然想获取父shell的可执行路径(而不是PID),以下方法可以实现:test ! -z "$shell" && set empty && set pid="$$$empty" || test ! -z "$fish_pid" && set pid "$fish_pid" || export pid="$$$empty"; ps -o pid,ppid | grep -E "^ *$pid" | grep -o '[^ ]*$' | xargs -I ppid readlink -f "/proc/ppid/exe" | cat
- Seantest ! -z "$shell" && set empty && set pid="$$$empty" || test ! -z "$fish_pid" && set pid "$fish_pid" || export pid="$$$empty"; readlink -f "/proc/$pid/exe" | cat
。 - Seanecho "$SHELL"
/bin/bash
/bin/sh
的参考。 - kosBash
,因为这是Ubuntu上的默认shell”,所以答案符合问题。 - kosps -p "$$"
的答案在bash和可能其他shell中有效,但在fish(Friendly Interactive SHell)中无效。在fish中,您应该运行ps -p %self
。所以我不确定是否有任何一个命令可以告诉您正在使用的是哪个shell。您可能需要尝试这两个命令,或者可能还需要尝试其他命令来确定。 - frederickjh$$
变量实际上是由POSIX定义的,并且在绝大多数的shell中都可以使用。Fish决定在这里不遵循标准,所以我认为可以忽略它。我可以确认,在sh、dash、bash、zsh、ksh、ash、tcsh和csh中,$$
按预期工作。事实上,就我所知,除了fish之外,我想不出还有哪个shell不能使用它。 - terdonlsof -p "$$" | grep -m 1 txt | xargs -n 1 | tail -n 1
/usr/local/Cellar/bash/5.1.8/bin/bash
/bin/zsh
chsh
命令。You will use a program called chsh. There is a interactive method and non-interactive method. Type the following into your terminal:
INTERACTIVE METHOD
$ chsh
This results in a brief dialog in which the user is prompted first for their password and then for the full path of the desired new shell.
Caution should be exercised when changing one's default shell because it is possible to make an error that only the root user (i.e., system administrator) can repair (although it should be easy for a skilled user to repair it on a home system). In particular, it is important to first test the shell temporarily in the current session and then to make certain that a valid shell name is being entered when making the permanent change.
NON-INTERACTIVE METHOD
I will use csh as again an example.
$ chsh -s /bin/csh
The
-s
sets it for you without having to go into the editor to do it.Once this is executed successfully, then
echo $SHELL
will still say that you are in the same shell as before. However, you need to log out and back in for the change to take effect. Now doecho $SHELL
. You should see it shows the new shell.
/bin/sh
,它是一个指向 /bin/bash
的符号链接。sh
,这会让提问者认为它是 Bourne shell 而不是 GNU bash,除了 this one 给出的 /bin/bash
。$ echo $SHELL
/bin/sh
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 May 31 16:15 /bin/sh -> bash
$ /bin/sh --help
GNU bash, version 4.2.10(1)
Usage: /bin/sh [GNU long option] [option] ...
/bin/sh [GNU long option] [option] script-file ...