Linux Bash Shell(Script)

Basic Concepts

  1. Pipe
    Represented by symbol: "|", pipe directs the stdout of the last command to the stdin of the next command.
    Example (directs the result of find command to grep command):
    find ./src/* | grep .java

  2. Environmental Variable
    export ABC=$(find ./src/* | grep .java)

Arguments in Bash Commands

Arguments in bash commands are all considered as string value. However, double quotations is optional and often omitted. Essentially, bash variables are character strings but arithmetic operations is allowed through "let" tool.


stat -x abc.txt

Execution Sequence

All commands in a bash script will be executed sequencially unless they are directed to be executed in the background (by terminating with a single amperstand symbol "&")

When preceded by double amperstand symbol "&&", the following command will be executed only when the previous command return a zero status code.

By default, commands will be executed sequentially regardless of the exit code of the previous command.


It closes standard input (the program will not be able to read any input, even if it is run in the foreground. it is not halted, but will receive an error code or EOF).
It redirects standard output and standard error to the file nohup.out, so the program won't fail for writing to standard output if the terminal fails, so whatever the process writes is not lost.
It prevents the process from receiving a SIGHUP (thus the name).