我怎么知道我的shell是什么类型的

我怎么知道我的shell是什么类型的?即是传统的sh,bash,ksh,csh,zsh等.

请注意,检查$SHELL或$0将不起作用,因为$SHELL不是由所有shell设置的,因此如果您在一个shell中启动,然后再启动另一个shell,那么您仍然可以使用旧的SHELL.

$0只会告诉你shell二进制文件的位置,但是不告诉你/ bin / sh是一个真正的Bourne shell还是bash.

我认为答案将是“尝试一些功能,看看什么休息”,所以如果有人可以指出一个这样做的脚本,那将是很棒的.

这是我在.profile中使用的:
# .profile is sourced at login by sh and ksh. The zsh sources .zshrc and
# bash sources .bashrc. To get the same behavIoUr from zsh and bash as well
# I suggest "cd; ln -s .profile .zshrc; ln -s .profile .bashrc".
# Determine what (Bourne compatible) shell we are running under. Put the result
# in $PROFILE_SHELL (not $SHELL) so further code can depend on the shell type.

if test -n "$ZSH_VERSION"; then
  PROFILE_SHELL=zsh
elif test -n "$BASH_VERSION"; then
  PROFILE_SHELL=bash
elif test -n "$KSH_VERSION"; then
  PROFILE_SHELL=ksh
elif test -n "$FCEDIT"; then
  PROFILE_SHELL=ksh
elif test -n "$ps3"; then
  PROFILE_SHELL=unkNown
else
  PROFILE_SHELL=sh
fi

它在ksh88,ksh95,pdksh或mksh等之间没有很好的区别,但是在十多年以来,已经证明对我来说是按照我在家的所有系统(BSD,SunOS,Solaris,Linux,Unicos,HP-UX,AIX,IRIX,MicroStation,Cygwin.)

我没有看到需要检查.profile中的csh,因为csh在启动时提供其他文件.你写的任何脚本不需要检查csh和Bourne的遗产,因为你明确地在shebang行中命名翻译.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...