Title here
Summary here
variable_name=value
$variable_name
if [ condition ]; then
# code to execute if condition is true
else
# code to execute if condition is false
fi
For loop:
for item in list; do
# code to execute for each item in the list
done
While loop:
while [ condition ]; do
# code to execute while condition is true
done
Declare a function:
function_name() {
# code to execute
}
Call a function: function_name
read variable_name
echo "message"
if [ -f file_path ]; then ...
touch file_path
rm file_path
$1
, $2
, …exit error_code
trap
:trap "error_handling_function" ERR
Single-line comment: # comment
Multi-line comment:
: '
This is a
multi-line comment
'
&&
): Execute the next command only if the previous command succeeds.||
): Execute the next command only if the previous command fails.command1 && command2
command2
will only be executed if command1
succeeds.command1 || command2
command2
will only be executed if command1
fails.;
) to chain multiple commands on the same line.command1 ; command2 ; command3
command1
, command2
, and command3
will be executed sequentially.if
statement to control the flow of commands based on conditions.if [ condition ]; then
# code to execute if condition is true
else
# code to execute if condition is false
fi
if
block will be executed if the condition is true. Otherwise, the code inside the else
block will be executed.For more information, refer to the Bash documentation.