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

前端之家收集整理的这篇文章主要介绍了我怎么知道我的shell是什么类型的前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我怎么知道我的shell是什么类型的?即是传统的sh,bash,ksh,csh,zsh等.

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

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

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

这是我在.profile中使用的:
  1. # .profile is sourced at login by sh and ksh. The zsh sources .zshrc and
  2. # bash sources .bashrc. To get the same behavIoUr from zsh and bash as well
  3. # I suggest "cd; ln -s .profile .zshrc; ln -s .profile .bashrc".
  4. # Determine what (Bourne compatible) shell we are running under. Put the result
  5. # in $PROFILE_SHELL (not $SHELL) so further code can depend on the shell type.
  6.  
  7. if test -n "$ZSH_VERSION"; then
  8. PROFILE_SHELL=zsh
  9. elif test -n "$BASH_VERSION"; then
  10. PROFILE_SHELL=bash
  11. elif test -n "$KSH_VERSION"; then
  12. PROFILE_SHELL=ksh
  13. elif test -n "$FCEDIT"; then
  14. PROFILE_SHELL=ksh
  15. elif test -n "$PS3"; then
  16. PROFILE_SHELL=unknown
  17. else
  18. PROFILE_SHELL=sh
  19. fi

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

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

猜你在找的Bash相关文章