Shell and Terminal

A terminal provides an interface for entering text and displaying output. A shell interprets command language and runs commands. Bash and zsh are shells; Linux is an operating-system environment. A terminal window can run different shells, and a shell script can run without an interactive terminal.

Before an external program runs, the shell can expand variables and filename patterns, arrange redirections, and determine the arguments passed to it. This explains why quoting changes behavior. If a variable contains a directory name with a space, an unquoted expansion can become more than one argument. Double quotes preserve that value as one argument while still allowing variable expansion.

Commands also depend on context. A relative path is interpreted from the current working directory. An external command name without a slash is normally found through PATH, although a shell may first resolve an alias, function, or builtin. A job started by a scheduler can have a different directory, environment, and account from an interactive session.

When a command works in a terminal but fails in a job, compare those contexts and the actual shell before changing the data. Explicitly launching Bash selects Bash semantics; a script’s shebang is used when the script is executed directly, but running it through a different interpreter selects that interpreter instead. Quoting keeps argument boundaries intact; it does not validate that a path is the intended one.

Reference: GNU Bash: What is a shell?. Practice these ideas in Linux, the Shell, and Git for Data Work.


Discover more from Insightful Data Lab

Subscribe to get the latest posts sent to your email.

Similar Posts

Questions, corrections, or additional insights?

This site uses Akismet to reduce spam. Learn how your comment data is processed.