The commands to inspect the state of the current shell environment
You wouldn't need to know such stuff for daily use of your PC, but it excites me so much and I don't wanna forget about this, so I will leave a record for it here. This articled has been made by GPT mainly, and that's why this is written in English.
echo $-
hBs
echo $0
/bin/bash
echo $PS1
(nothing got printed)
Bash in 100 Seconds
In case, you forgot what bash means and what it is doing, check out this video.
Command: echo $-
- Output: hBs
Explanation: This command prints the current shell options that are enabled. Each letter corresponds to a specific shell option:
- h: Hash all commands in the path
- B: The shell is running in POSIX mode
- s: Commands are being read from standard input (indicating an interactive shell session)
Hash refers to the internal hash table used by the shell to store the locations of commands to speed up their execution.
POSIX (Portable Operating System Interface) mode refers to a standardized mode of operation for Unix-like operating systems and shells. When a shell runs in POSIX mode, it aims to conform to the POSIX standard, which ensures compatibility and portability across different Unix-like systems
Command: echo $0
- Output: /bin/bash
Explanation: This prints the name of the shell or shell script currently being executed. In this case, it indicates that you are using the bash shell, and it was invoked as /bin/bash.
Command: echo $PS1
- Output: (nothing got printed)
Explanation: This prints the value of the primary prompt string (PS1). If nothing is printed, it means that PS1 is either unset or set to an empty value. The PS1 variable typically defines the appearance of the command prompt in the shell. A typical default value for PS1 might be something like \u@\h:\w\$
, which displays the username, hostname, and current working directory.
Summary of What This Means
Shell Options ($-): You are in an interactive bash shell with certain options enabled (h, B, s).
Current Shell ($0): The current shell is bash, and it was invoked directly from /bin/bash.
Prompt String ($PS1): The primary prompt string (PS1) is not set or is empty. This could result in a minimal or default prompt appearance, or the shell might be using a different variable or method for the prompt if PS1 is unset.