-
Notifications
You must be signed in to change notification settings - Fork 3
Scripting
#Command substitution
`some command`
plugs the some command
output into some other context.
Currently backticks are deprecated in favour of $(some command)
form which:
- permits nesting
$(some command $(some nested))
- treats
\\
differently
#Process substitution
<(command_list)
Feeds the output of processes into the stdin of another process (piping allows only one
command output to be redirected into stdin of another process).
The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to the current command as the result of the expansion.
#Bash Shell implementation ##Built-in variables Positional parameters
-
$#
number of command line arguments
Special
-
$?
last command's exit code
##Test constructs
if
statement tests wheter exit status of command is equal to 0
if test command; then
#sth
fi
bash has alias for test
command and is called [
so the statement becomes:
if [ command ]; then
fi
With Bash 2.02 extended test statement was introduced:
if [[ command ]]; then
fi
Extended test statement is not compliant with POSIX.
Features:
- No need to quote variables (in
[
not quoted variables like "something with spaces" will yield error: too many arguments) - Regular expression matching with
=~
e.g.[[ $variable =~ .*string ]]
- Wildcard matching e.g.
[[ $(lxc-ls) == *"desired_container"* ]]
#AWK print the quote sign
awk 'BEGIN { print "Here is a single quote <'"'"'>" }' #this is concat of three strings '...' "'" '...'
awk 'BEGIN { print "Here is a single quote <'\''>" }'
simple examples:
#longest line in data file
awk '{ if (length($0) > max) max = length($0) }
END { print max }' data
# Print every line that has at least one field
awk 'NF > 0' data
you can have multiple rules in awk (first goes first rule, then second, if line contains both patterns then will be processed two times)
awk '/12/ { print $0 }
/21/ { print $0 }' data
awk env variables:
-
AWKPATH
- contains awk programs -
AWKLIBPATH
- contains extensions (can be written in C/C++)
#References
- https://google.github.io/styleguide/shell.xml
- https://github.com/robbyrussell/oh-my-zsh/wiki/Coding-style-guide
- http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
- https://www.kernel.org/doc/Documentation/process/coding-style.rst
- https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org
- http://www.tldp.org/LDP/abs/html/internalvariables.html
- http://mywiki.wooledge.org/BashFAQ
- http://mywiki.wooledge.org/BashPitfalls
- General
- OS
- Networks
- Configuration
- Protocols
- Link layer
- Sockets
- Routing
- Tunneling
- Debugging
- LoRa
- Virtualization
- Infrastructure as a code
- Desktop environments
- Monitoring
- Benchmarking