如何获得使用脚本的shell中运行的名字吗? [英] How to get the name of the shell running using a script?

查看:147
本文介绍了如何获得使用脚本的shell中运行的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行打印shell的名称运行它的shell脚本。

I'd like to run a shell script that prints the name of the shell running it.

到目前为止,我一直在使用回声$ SHELL ,但该变量可能没有设置,不给运行脚本的当前shell的名称。

So far I've been using echo $SHELL but that variable may not be set and does not give the name of the current shell running the script.

我试着 PS -p $$ 但在脚本它给我的脚本文件的名称,直接在终端使用它时,这只作品

I've tried with ps -p $$ but this only works when using it directly in the terminal as in the script it gives me the name of the script file.

我还没有找到一个很好的解决这个问题。

I have not found a good solution to this problem.

当前脚本:

#!/bin/bash
echo $SHELL

感谢

编辑:以防万一,我的意思是我想获得通过使用脚本运行该脚本的命令间preTER的名称

Just in case, I mean that I want to get the name of the command interpreter running the script by using a script.

推荐答案

难道这些方针的东西你想要什么?

Does something along these lines do what you want?

me@server2:~$ cat test
#!/bin/sh
X=$(ps h -p $$ -o args='' | cut -f1 -d' ')
echo "Running --> $X"    

me@server2:~$ ./test
Running --> /bin/sh
me@server2:~$ sh test
Running --> sh
me@server2:~$ bash test
Running --> bash
me@server2:~$    

这篇关于如何获得使用脚本的shell中运行的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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