如何确定我正在使用的当前shell ?

仅仅ps命令的输出就足够了吗?

如何在不同风格的Unix中实现这一点?


当前回答

你可以使用echo $SHELL|sed "s/\/bin\// g"

其他回答

Try

ps -p $$ -oargs=

or

ps -p $$ -ocomm=

如果你只是想确保用户正在使用Bash调用脚本:

if [ -z "$BASH" ]; then echo "Please run this script $0 with bash"; exit; fi

或参考

if [ -z "$BASH" ]; then exec bash $0 ; exit; fi

请使用以下命令:

ps -p $$ | tail -1 | awk '{print $4}'
echo $$ # Gives the Parent Process ID 
ps -ef | grep $$ | awk '{print $8}' # Use the PID to see what the process is.

你如何知道你当前的shell是什么?

我对打印父进程的变体:

ps -p $$ | awk '$1 == PP {print $4}' PP=$$

当AWK可以为您运行不必要的应用程序时,不要运行它。