Tutorial by Examples

Create a new file called hello.sh with the following content and give it executable permissions with chmod +x hello.sh. Execute/Run via: ./hello.sh #!/usr/bin/env bash # Note that spaces cannot be used around the `=` assignment operator whom_variable="World" # Use printf to sa...
Interactive Shell The Bash shell is commonly used interactively: It lets you enter and edit commands, then executes them when you press the Return key. Many Unix-based and Unix-like operating systems use Bash as their default shell (notably Linux and macOS). The terminal automatically enters an int...
help <command> This will display the Bash help (manual) page for the specified built-in. For example, help unset will show: unset: unset [-f] [-v] [-n] [name ...] Unset values and attributes of shell variables and functions. For each NAME, remove the corresponding variable or ...
The following will prompt a user for input, and then store that input as a string (text) in a variable. The variable is then used to give a message to the user. #!/usr/bin/env bash echo "Who are you?" read name echo "Hello, $name." The command read here reads one line of ...
#!/bin/bash deploy=false uglify=false while (( $# > 1 )); do case $1 in --deploy) deploy="$2";; --uglify) uglify="$2";; *) break; esac; shift 2 done $deploy && echo "will deploy... deploy = $deploy" $uglify && echo "will...
$ cat hello.sh #!/bin/bash echo "Hello World" $ bash -x hello.sh + echo Hello World Hello World The -x argument enables you to walk through each line in the script. One good example is here: $ cat hello.sh #!/bin/bash echo "Hello World\n" adding_string_to_number=...
Quoting is important for string expansion in bash. With these, you can control how the bash parses and expands your strings. There are two types of quoting: Weak: uses double quotes: " Strong: uses single quotes: ' If you want to bash to expand your argument, you can use Weak Quoting: ...

Page 1 of 1