Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • "So when you're outside the script, these variables aren't available" What do you mean by "outside the script", because I can see the values of these variables in my terminal. Commented Oct 25, 2017 at 22:30
  • 2
    @user7681202: Which ones can you see in your terminal? $0 will point to your current terminal process (likely bash) and $? is simply the exit code of the last process. Commented Oct 25, 2017 at 22:33
  • I tried to run the gnome-terminal with arguments (gnome-terminal Hello World). I could see $0, but I could not see $1 and $2. Commented Oct 25, 2017 at 22:36
  • @Jesse_b Thank you, I've added the content of $0 into the answer. Commented Oct 25, 2017 at 22:37
  • 1
    @user7681202 The gnome-terminal isn't shell, it's terminal emulator (like xterm, konsole etc.). The shell runs inside the terminal and it can be bash/sh/zsh/tcsh and many more. The script is executable file with proper header (like #!/bin/bash) and content interpretable by the shell specified in the mask. It usually uses suffix .sh Commented Oct 25, 2017 at 22:41