Advanced Search
Search Results
9 total results found
Condition
If Statement If the exit code of command is 0, then execute the content of then. if command then ... fi Another form. if command; then ... fi Else if command; then ... else ... fi Elif if command; then ... elif command; then ... fi ...
Function
Creating a Function function name { commands } or name() { commands } Function Return Value There are multiple forms of return values. Using $? Represents the exit status code of the last command in the function. echo $? Using Return #!/usr/bin/en...
Input
Positional Parameters Positional Parameters, script positional parameters. $0: script name, including path. $1: the first argument, and so on. ${10}: arguments greater than 9 need to use curly braces. #!/usr/bin/env bash echo $0 echo $1 ./foo a ./foo a ...
Loop
For Statement for var in list do ... done The var variable can be normally used outside the loop body. #!/usr/bin/env bash for var in apple banana do echo "hello $var" done echo "outside $var" hello apple hello banana outside var Storing a list in...
Output
Standard File Descriptors Standard File Descriptors. Name Number Description STDIN 0 Standard Input STDOUT 1 Standard Output STDERR 2 Standard Error Standard Input The cat command reads content from the standard input by default. If you run cat ...
Parameter Expansion
In Bash, parameter expansion is a mechanism for manipulating and handling the contents of variables. Through parameter expansion, you can get the value of a variable, modify the value of a variable, or provide a default value for an unset variable. Shell Param...
Signal
Bash Shell By default, the Bash Shell ignores the SIGQUIT(3) and SIGTERM(15) signals, so executing the following commands will not have any effect ($$ is the process ID of the current Shell). kill -3 $$ kill -15 $$ If the SIGHUP(1) signal is received, the B...
Special Parameters
Parameters: $? The exit code of the previous command or script, 0 for success, non-0 for failure. ls 404 echo $? Will output 2, indicating failure. The return code can be specified in scripts using exit. Parameters: $# Indicates the number of arguments pas...
Basic Syntax
Shebang #!/usr/bin/env bash Variable Assignment No spaces are allowed around the = sign. name=foo Double Quotes Can interpret variables. name=foo echo "hello, $name" # hello, foo echo "hello, \$\$" # hello, $$ echo "hello, \"\"" # hello, "" Single Quo...