Skip to main content
Advanced Search
Search Terms
Content Type

Exact Matches
Tag Searches
Date Options
Updated after
Updated before
Created after
Created before

Search Results

9 total results found

Condition

Linux Command Line and Shell Scripting ... Script

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 ...

linux
lclssb
script
operating-system

Function

Linux Command Line and Shell Scripting ... Script

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...

operating-system
linux
lclssb
script

Input

Linux Command Line and Shell Scripting ... Script

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 ...

linux
operating-system
lclssb
script

Loop

Linux Command Line and Shell Scripting ... Script

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...

operating-system
linux
lclssb
script

Output

Linux Command Line and Shell Scripting ... Script

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 ...

script
lclssb
operating-system
linux

Parameter Expansion

Linux Command Line and Shell Scripting ... Script

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...

operating-system
linux
lclssb
script

Signal

Linux Command Line and Shell Scripting ... Script

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...

script
operating-system
linux
lclssb

Special Parameters

Linux Command Line and Shell Scripting ... Script

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...

operating-system
linux
lclssb
script

Basic Syntax

Linux Command Line and Shell Scripting ... Script

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...

operating-system
linux
lclssb
script