What is Shell?

A program that reads and interprets the commands a user types, starts programs and shows the results. On Linux, bash and zsh are widely used. It provides wildcard expansion, variables, redirection and pipes, and job control, and it can also run files of commands (shell scripts) to automate work. The name comes from its role as a "shell" around the kernel, the core of the OS, standing between it and the user.

Japanese name: シェル

Shell appears in 10 practice questions across 2 topics, including Linux and Command-Line Basics, Linkers, Loaders & Executables.

Field: Linux and Command-Line Basics

Until a command runs

The shell reads a line of input, expands variables and wildcards (globbing) and processes quotes, then splits it into a command name and arguments. If the command name contains no slash, it runs either a built-in command or the first executable found by searching the directories in the PATH environment variable in order. Reconnecting standard input, standard output and standard error as specified by redirections and pipes is also the shell's job.

Shell scripts

If a file of commands has a shebang such as #!/bin/bash on its first line and is given execute permission, it can be run just like a program. Arguments are referred to as $1 and $2, their number as $#, and the exit status of the previous command as $?, and if, for and while express branches and loops. Scripts are often used to automate fixed procedures such as batch-running simulations or summarizing logs.

Various shells

Besides bash, which is widely used on Linux, there are zsh and fish with rich interactive features, and dash, which is light and starts quickly. Scripts written only with the sh syntax defined by the POSIX standard run in many shells. Environment-setup scripts of EDA tools are still sometimes written in the csh family (csh, tcsh) syntax, and a settings file loaded with source has to match the kind of shell.

Try it: questions about Shell

touch creates a new file from 666, and mkdir a new directory from 777, with the umask bits removed. Which of the following is the correct pair of permissions when a new file and a new directory are created in a shell whose umask is 027?

  1. Afile 637, directory 750
  2. Bfile 640, directory 750
  3. Cfile 750, directory 750
Show answer and explanation

Answer: B. file 640, directory 750

The umask gives the permission bits to "remove" from newly created files and directories. 027 removes write (2) from the group and read, write and execute (7) from others, so a file becomes rw-r----- (640) from 666 and a directory becomes rwxr-x--- (750) from 777. This is not octal subtraction but bitwise removal (666 AND NOT 027). With the commonly used umask 022, the same calculation gives 644 for files and 755 for directories.

FAQ

What is the difference between a shell and a terminal?

A terminal (terminal emulator) is a program that serves as the window that displays characters and receives keyboard input. The shell runs inside it and interprets the received strings as commands and executes them. You can switch from bash to zsh within the same terminal.

What is the difference between "source file" and "./file"?

Running ./file makes a new shell process run the script, so variables or the current directory changed inside it are not kept in the original shell when it ends. source (or .) runs the file's contents in the current shell, so settings such as environment variables remain. That is why settings files that prepare a tool's environment are loaded with source.

Shell in the explanations

Questions that mention Shell (10)

  1. touch creates a new file from 666, and mkdir a new directory from 777, with the umask bits removed. Which of the following is the correct pair of permissions when a new file and a new directory are created in a shell whose umask is 027?
  2. When the two lines above are run in a shell, which of the following are the characters shown?
  3. In a shell script, in which of the following cases is the condition of the if above true?
  4. When a C main function ends with "return 3;", what generally happens to the value 3?
  5. A directory contains six files: a1.txt, a2.txt, a10.txt, b1.txt, c1.txt and a1.csv. Which of the following is the number of files shown when "ls [ab]?.txt" is run in this directory?
  6. Which of the following describes the files found when find /data -name "*.log" -mtime +7 -size +100M is run with GNU find?
  7. On a server reached over SSH, a long-running task was started with "./run.sh &", and when the connection was closed the task stopped too. Which of the following is the most appropriate way to start it so that it keeps running after the connection is closed?
  8. When the commands above are run in order, which of the following is the output of the two echo commands?
  9. An executable script run.sh in the current directory gives "command not found" when run by typing "run.sh", but runs when typed as "./run.sh". Which of the following is the reason?
  10. When the commands above are run in order, which of the following is the pair of outputs of the two bash -c commands?

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Related terms

Variable Environment variable File permissions Return value SSH Argument cron Git grep Hard link

Back to the glossary