简体   繁体   English

获取linux shell名称

[英]get linux shell name

In my program I need to output to user which shell he is using. 在我的程序中,我需要向用户输出他正在使用哪个shell。 So in file /etc/udate-motd.d/00-header I wrote printf "$SHELL" but the problem is that even when I switching my shell to zsh, $SHELL is still equal to /bin/bash. 因此,在文件/etc/udate-motd.d/00-header我写了printf "$SHELL"但问题是,即使我将Shell切换到zsh,$ SHELL仍等于/ bin / bash。 I searched through the internet and found that I can bo it by using MyShell='ps -hp $$' , and here is again a problem. 我通过互联网搜索,发现可以通过使用MyShell='ps -hp $$'MyShell='ps -hp $$'它,这又是一个问题。 When I use it MyShell is a string with number of processes ( /etc/update-motd.d/00-header is also there) but there no word zsh . 当我使用MyShell时,它是一个带有进程数的字符串( /etc/update-motd.d/00-header也存在),但是没有zsh这个词。

So how can I understand which shell use the logging in person. 因此,我如何才能亲自了解哪个shell使用日志记录。

"the internet" gave you one kind of ps syntax. “互联网”为您提供了一种ps语法。 You've tagged this linux, so don't use BSD syntax. 您已标记了此linux,因此请勿使用BSD语法。 Try this: 尝试这个:

ps hp $$ -o cmd

no dash 没有破折号

The users shell is determined in /etc/passwd. 用户外壳程序在/ etc / passwd中确定。 Why not take the information from there? 为什么不从那里获取信息? You could 你可以

grep $USER /etc/passwd | cut -f7 -d:

to get the shell. 得到外壳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM