我怎么知道我的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行中命名翻译.
原文地址:https://www.jb51.cc/bash/386760.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。