我如何知道我的外壳是什么类型 [英] How do I tell what type my shell is

查看:96
本文介绍了我如何知道我的外壳是什么类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I tell what type my shell is? ie, whether it's traditional sh, bash, ksh, csh, zsh etc.

请注意,检查$SHELL$0不会起作用,因为并非所有shell都设置了$SHELL,因此,如果您在一个shell中启动,然后再启动另一个shell,您可能仍会使用旧的.

Note that checking $SHELL or $0 won't work because $SHELL isn't set by all shells, so if you start in one shell and then start a different one you may still have the old $SHELL.

$0仅告诉您shell二进制文件在哪里,而没有告诉您/bin/sh是真正的Bourne shell还是bash.

$0 only tells you where the shell binary is, but doesn't tell you whether /bin/sh is a real Bourne shell or bash.

我认为答案将是尝试一些功能,看看有什么坏处",因此,如果有人可以指出要执行此操作的脚本,那将是很好的选择.

I presume that the answer will be "try some features and see what breaks", so if anyone can point me at a script that does that, that'd be great.

推荐答案

这是我在.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.)

It does not make fine distinctions between ksh88, ksh95, pdksh or mksh etc., but in more than ten years it has proven to work for me as designed on all the systems I were at home on (BSD, SunOS, Solaris, Linux, Unicos, HP-UX, AIX, IRIX, MicroStation, Cygwin.)

我不认为需要检查.profile中的csh,因为csh在启动时会获取其他文件. 您编写的任何脚本都不需要检查csh vs Bourne-heritage,因为您在shebang行中明确命名了解释器.

I don't see the need to check for csh in .profile, as csh sources other files at startup. Any script you write does not need to check for csh vs Bourne-heritage because you explicitly name the interpreter in the shebang line.

这篇关于我如何知道我的外壳是什么类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆