DXZ
DXZ

Reputation: 495

Why is "echo $SHELL" always returning /bin/tcsh

I have the following simple shell script:

[test.sh]

#! /bin/bash
echo $SHELL

Why am I am always getting a console output of /bin/tsch in all the following scenarios?

1) In the terminal, run the following:

% ./test.sh

2) In the terminal, run the following:

% bash
$ ./test.sh

3) In the terminal, run the following:

% bash ./test.sh

As you can probably tell from the % cursor, the terminal starts with tcsh by default. I am confused by why #! /bin/bash in the script and bash in the command line are not affecting the value of $SHELL.

Upvotes: 0

Views: 860

Answers (1)

glenn jackman
glenn jackman

Reputation: 247092

See Bash Variables in the manual:

SHELL

The full pathname to the shell is kept in this environment variable. If it is not set when the shell starts, Bash assigns to it the full pathname of the current user’s login shell.

My emphasis.

If you want the path to the current bash executable, use $BASH. See the above link to the docs.

Upvotes: 1

Related Questions