0

I am currently playing CTF in OverTheWire website . I was stuck on 32nd Level [ https://overthewire.org/wargames/bandit/bandit33.html ] to get password for next Level . Command to access Level 32 - ssh bandit32@bandit.labs.overthewire.org -p 2220 and the password is 56a9bf19c63d650ce78e6ec0354ee45e .

SO when I login I get made up shell called UPPERCASE SHELL . Which takes commands and converts them to UPPERCASE throwing "command not found error " . When I run $SHELL , all I can see is a banner called "WELCOME TO UPPERCASE SHELL" . So I googled for walk-through after being stuck on for 3 hours . SO one of the guy enterd $0 which took him to Bourne Shell [ I guess ] . SO what is the difference between $0 and $SHELL .

By my understanding $SHELL is default shell [ UPPERCASE_SHELL ] which I verified after running cat /etc/paswd | grep bandit32 . SO what is $0 . If $0 is current shell then I should get the same banner[ UpperCase ] as output . How come I landed Bourne Shell .

Bottom line . what are these 2 shell variables how do thesework in this context ?

1
  • I can't tell if you're asking about the specifics of some (made up) shell that only exists in that puzzle, or about how those variable and parameter work in actual mainstream shells. If the former, there's probably no way for us to know; if the second, it doesn't answer anything about how the made up shell in the puzzle behaves...
    – ilkkachu
    Sep 16, 2021 at 19:44

2 Answers 2

1

$SHELL is a funny variable. For most shells, it holds the name of your login shell (you see this in /etc/passwd). It doesn't automatically change if you launch a different shell interpreter.

For example, my login shell is fish. Let's see what different shells do with $SHELL:

$ set -e SHELL; bash -c 'echo $SHELL'
/usr/local/bin/fish
$ set -e SHELL; ksh -c 'echo $SHELL'
/bin/sh
$ set -e SHELL; zsh -c 'echo $SHELL'

$ set -e SHELL; dash -c 'echo $SHELL'

$ set -e SHELL; fish -c 'echo $SHELL'

set -e var is fish's way of unsetting a variable.

  • bash sets SHELL to my login shell.
  • ksh uses a default shell.
  • zsh and dash and fish put no special meaning on SHELL.

So, $SHELL is simply informative at best. I wouldn't rely on it holding any magic value.


The value of SHELL is actually set by login, before the shell is invoked. From the (BSD) login manual on my Mac:

The login utility enters information into the environment (see environ(7)) specifying the user's home directory (HOME), command interpreter (SHELL), search path (PATH), terminal type (TERM) and user name (both LOGNAME and USER).

2
  • Thanks man for the help . Been banging my head for 3 hours to figure solution and another hour trying to understand it .
    – teja_M19
    Sep 16, 2021 at 20:26
  • @teja_M19 Good! If this solves your issue, please consider accepting the answer. Accepting an answer marks the issue as resolved.
    – Kusalananda
    Sep 16, 2021 at 20:33
1

$SHELL should tell you the shell name - see glenn's answer for how vaguely that variable should be considered.

$0 is the name of the current script.

Make a shell script called test.sh like this:

#!/bin/bash
echo My shell is $SHELL
echo My script is called $0

and see what happens when you run it. Changing the shebang to #!/bin/zsh will not change the result. Again see glenn's answer.

As for your game: There anything might be happening. It might just be some emulated shell for the game or whatever simulated game element. No one can tell.

4
  • 2
    in particular, in Bash SHELL "expands to the full pathname to the shell. If it is not set when the shell starts, Bash assigns to it the full pathname of the current user’s login shell." -- gnu.org/software/bash/manual/bash.html#Shell-Variables (so it might not be actually related in any way, e.g. (unset SHELL; bash -c 'echo $SHELL') might well print /usr/bin/zsh...)
    – ilkkachu
    Sep 16, 2021 at 19:46
  • @ilkkachu answer adapted.
    – FelixJN
    Sep 16, 2021 at 20:12
  • Thanks dude for your help and time
    – teja_M19
    Sep 16, 2021 at 20:26
  • @teja_M19 Good! If this solves your issue, please consider accepting the answer. Accepting an answer marks the issue as resolved.
    – Kusalananda
    Sep 16, 2021 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.