如何确定我正在使用的当前shell ?
仅仅ps命令的输出就足够了吗?
如何在不同风格的Unix中实现这一点?
如何确定我正在使用的当前shell ?
仅仅ps命令的输出就足够了吗?
如何在不同风格的Unix中实现这一点?
当前回答
你可以试试:
ps | grep `echo $$` | awk '{ print $4 }'
Or:
echo $SHELL
其他回答
echo $$ # Gives the Parent Process ID
ps -ef | grep $$ | awk '{print $8}' # Use the PID to see what the process is.
你如何知道你当前的shell是什么?
我特别喜欢Nahuel Fouilleul的解决方案,但我不得不在Ubuntu 18.04 (Bionic Beaver)上使用内置的Bash shell运行它的以下变体:
bash -c 'shellPID=$$; ps -ocomm= -q $shellPID'
没有临时变量shellPID,例如:
bash -c 'ps -ocomm= -q $$'
只会输出ps。也许你们不是都在使用非交互模式,这是有区别的。
Try
ps -p $$ -oargs=
or
ps -p $$ -ocomm=
Ps是最可靠的方法。SHELL环境变量不能保证被设置,即使设置了,也很容易被欺骗。
你可以试试:
ps | grep `echo $$` | awk '{ print $4 }'
Or:
echo $SHELL