Linked Questions

74
votes
11answers
95k views

How to test what shell I am using in a terminal?

How to check what shell I am using in a terminal? What is the shell I am using in MacOS?
9
votes
5answers
5k views

How do I *reliably* and *simply* get the current shell interpreter name?

I'm looking for a simple and reliable way to get the name of the current shell from inside a script or a sourced file (not from the command line). I would have expected to just do $(basename "$SHELL")...
4
votes
4answers
482 views

POSIX-compatible/cross-shell way to get version of running shell?

Is there a POSIX-compatible way or a way, which works on all shells, to get the version number of the shell, which is running? With $SHELL ps -p$$ -ocmd= you can get the name/binary, so $SHELL --...
7
votes
3answers
184 views

'switch' based on shell

I would like to source (i.e. not call) a script from any shell (bash/csh are the primary targets, but fish, zsh, ksh, and rc would also be interesting). I would like if the script can be a single ...
4
votes
3answers
1k views

if/then/else man page

I would like to know if there is any man page documenting the construction of the most basic script commands like if/then/else, while, for each, and all the relative switches, like -eq, -e, -ge, and ...
8
votes
2answers
9k views

Inconsistency of stderr redirection between tcsh and other shells

I'm running into issues with redirection in tcsh. Consider the following commands: vi --version and vi --xxx. And let's assume this is on a machine where vi supports the --version option. The ...
7
votes
2answers
580 views

SHELL environment variable still points to zsh after using bash

I am trying to jump between zsh and bash. By default, I have zsh as my shell, I can know this by typing: echo $SHELL and I get /bin/zsh However, I want to open Bash, so I type /bin/bash; I assume I ...
3
votes
2answers
228 views

Test for a particular file format

This is a followup to Normal looking text file, detected by file as ASCII Pascal program text It seems file can't be trusted all the time. It seems possible that a particular file may be detected ...
3
votes
2answers
1k views

Writing scripts that use different commands in different shells [duplicate]

How can I write a script that is shell independent? I want to be able to run one script which will run in ksh, sh and bash. For example: If I have a line in my script like whence ls which will run in ...
2
votes
2answers
229 views

How to know, what SHELL is used when running a script? [duplicate]

How can I output that what shell is used to execute a script? Ex.: the $SHELL variable gives that what is the default shell for the given user. That is ok, but the given user can launch the script ...
1
vote
2answers
85 views

Can I combine ksh/zsh and other shells with Bash in the same workflow?

Can I combine ksh/zsh and other shells with Bash in the same workflow (shell session)? I am used to Bash but I might need some behavior available either in ksh or zsh. Could I use Bash with them, in ...
3
votes
1answer
8k views

Finding out what sh is [duplicate]

I am writing a set of scripts that I want to be portable, but I need to know whether sh on the current platform stands for bash, ksh, or ash. Is there a clear way to do it? What comes to my mind ...
1
vote
1answer
94 views

How to understand which shell a particular code belongs to without knowledge about the shell?

I get to understand that this code is for bash shell for f in $file.docked.[0-9][0-9][0-9] do mv $f $f.pdb done And this code is for tcsh shell foreach f ( file.docked.[0-9][0-9][0-9] ) mv $f ...
0
votes
1answer
1k views

Subshell and process substitution

Apologies if this is a basic question - I'm stuck trying to solve a larger problem, and it's come down to how a shell script is invoked - directly (shellScript.sh) or using sh shellScript.sh. Here's ...
0
votes
0answers
52 views

Add command output as variable; cross-platform syntax

1. Summary I don't find, how I can use command output as variable, use cross-platform syntax. 2. Example For example, I want get URL of my remote git repository: SashaChernykh@DESKTOP-EEOT0TN /...