Detect which shell is running




















For me, I have zsh installed and it's the current default, to change to bash, all I have to do type bash in the terminal. To switch back to zsh, type zsh — Yousuf Azad. You don't want to keep going back and forth that way because you stack up shell within shell within shell, and a fresh context within each.

In general it's best to type ctrl-d or exit to return to the previous shell. Best answer, should be chosen as answer. Agree to yousuf Azad on changing shell, but also agree to stacking issue indicated by Phill Apley.

Evan Benn Evan Benn 2 2 silver badges 4 4 bronze badges. Apparently this does not work in busybox, due to non posix compliance: ref: github. What does your first code block exemplify? Great answer, EvanBenn, thanks! Here is a tiny modification to allow it to work with shells like BusyBox , where the -p arg to ps isn't supported, and where there aren't a whole lot of other utilities like cut to help. I'm using your method to determine the shells used on a bunch of "free online Linux shell" websites, and it's great!

Show 1 more comment. I clarified the meaning of "currently" in my answer — kos. Fish has decided not to follow the standard here so I think it's fair to ignore it. In fact, off the top of my head I can't think of any other shell except fish where it doesn't work. Show 2 more comments. Pablo Bianchi 9, 3 3 gold badges 49 49 silver badges 89 89 bronze badges. Michael D Michael D 2 2 silver badges 7 7 bronze badges.

There are two modes: interactive, and; non-interactive. From Changing Shells - Changing your login shell which is permanent , and paraphrasing it slightly: You will use a program called chsh. Greenonline Greenonline 1, 6 6 gold badges 16 16 silver badges 24 24 bronze badges. Possibly the answer I've just added also addresses this issue? I'm not quite sure how cross-system it is, so would be interested to know how it works for you on that server. MikeBeaton MikeBeaton 7 7 bronze badges.

The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta. Now live: A fully responsive profile. Linked Related 4. This command outputs a string like bash. Here I'm only using ps , tail , and sed without GNU extesions; try to add --posix to check it. I'm sure tail can be removed, but my sed fu is not strong enough to do this. This works, though, only on KornShell -like shells ksh.

I like Nahuel Fouilleul's solution particularly, but I had to run the following variant of it on Ubuntu Would just output ps for me. Maybe you aren't all using non-interactive mode, and that makes a difference? About running an actually different shell than the name indicates, one idea is to request the version from the shell using the name you got previously:.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to determine the current shell I'm working on Ask Question.

Asked 11 years, 3 months ago. Active 1 month ago. Viewed k times. How can I determine the current shell I am working on? Would the output of the ps command alone be sufficient? How can this be done in different flavors of Unix? Improve this question. Peter Mortensen 29k 21 21 gold badges 97 97 silver badges bronze badges.

Testing for particular capabilities e. It appears that there is no simple answer to this question. If we can't query the shell, maybe the better approach is to always specify the shell. I'm not sure that this is always possible, but maybe it is more easily accomplished than people generally assume. Aniket, not so much help as you might think - that's only interested in interactive shell processes.

Add a comment. Active Oldest Votes. Improve this answer. See my solution above — DVK. Show 11 more comments. Matthew Slattery Matthew Slattery Of course, this will not work in fish, and possibly some other shells. In some minimal systems like a debian-slim docker container, ps might not be there. Show 1 more comment. Monolo 18k 16 16 gold badges 64 64 silver badges bronze badges.

Nahuel Fouilleul Nahuel Fouilleul This is a nice short one. The next line in my script has the equivalent for csh. I've found that if you do this from within a subshell then it can lead to spurious extra lines by matching the parent's PID as well as the actual shell process. If you just want to ensure the user is invoking a script with Bash: if [! Peter Lamberg Peter Lamberg 7, 3 3 gold badges 49 49 silver badges 64 64 bronze badges.

This should be the one closer to the top. Windows Batch note In GitLab The cmd shell remains included in future versions of GitLab Runner however, any new feature for Windows is to be tested and supported only for use with PowerShell. Only critical bugs and regressions to the cmd shell will be investigated and fixed. Windows Batch is the default shell used on Windows when shell is not specified. The example can be copied to your own group or instance for testing.

More details on what other GitLab CI patterns are demonstrated are available at the project page. Create an issue to suggest an improvement to this page. Product Create an issue if there's something you don't like about this feature.

Propose functionality by submitting a feature request. Join First Look to help shape new features.



0コメント

  • 1000 / 1000