Variables & Environment

Variable scoping, export, environment inspection, $PATH, $IFS, and Bash special variables.

Overview

Overview Bash variables and the environment are fundamental to shell scripting and interactive use. Getting them wrong causes subtle, hard-to-debug bugs. This chapter starts with how a variable is set and read, then follows it through functions and into child processes, and ends with the variables the shell sets for you.

Key concepts

  • export keyword
  • $PATH order
  • $IFS word splitting
  • $? and $@ vs $*

Interview questions

  • What is the difference between $@ and $* in bash? When does it matter?
  • How does the export keyword work, and what happens to variables without it in subshells?

Sign up free to read the full topic

More Linux topics

Start free on Cariara · Coding problems · System design studio