-
-
Save kirk86/5b346dfb8c1c397c024f to your computer and use it in GitHub Desktop.
cheatsheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
____ _ ____ _ _ ____ _ _ _ _ | |
| __ ) / \ / ___|| | | | / ___| |__ ___ __ _| |_ ___| |__ ___ ___| |_ | |
| _ \ / _ \ \___ \| |_| | | | | '_ \ / _ \/ _` | __/ __| '_ \ / _ \/ _ \ __| | |
| |_) / ___ \ ___) | _ | | |___| | | | __/ (_| | |_\__ \ | | | __/ __/ |_ | |
|____/_/ \_\____/|_| |_| \____|_| |_|\___|\__,_|\__|___/_| |_|\___|\___|\__| | |
kelvinchan.ca | |
Comparison | |
========== | |
test test command && logic AND | |
[ ] synonym for test command || logic OR | |
[[ ]] extended test ! logic NOT | |
let evaluate arithmetic expression | |
(( )) same as above | |
File Test Operators Integer Test Operators | |
------------------- ---------------------- | |
-f is a regular file? -eq is equal to? | |
-d is directory? -ne is not equal to? | |
-b is block device? -gt is greater than? | |
-c is char device? -ge is greater than or equal to? | |
-p is pipe? -lt is less than? | |
-h is symlink? -le is less than or equal to? | |
-S is socket? | |
-t is fd associated with Arithmetic Test Operators | |
a terminal device? ------------------------- | |
-e file exists? < is less than? | |
-s is zero size? <= is less than or equal to? | |
> is greater than? | |
-r has read permission? >= is greater than or equal to? | |
-w has write permission? | |
-x has execute permission? String Test Operators | |
-g is sgid flag set? --------------------- | |
-u is suid flag set? | |
-k is sticky bit set? = is equal to? | |
-O are you the owner? == is equal to? (synonym for =) | |
-G are you in the same group? != is not equal to? | |
-N is modified since last read? =~ matches extended regex? | |
-nt is newer than? < is less than? (in ASCII order) | |
-ot is older than? > is greater than? (in ASCII order) | |
-ef is hard linked to? -z is null or zero lengh? | |
-n is not null? | |
Shell Parameters Common Shell Variables | |
================ ====================== | |
$n the n-th positional param $TMPDIR temp directory | |
($0 is the name of the command) $PS3 prompt for select cmd | |
$* all positional params $REPLY return value of read cmd | |
$@ all positional params in an array $GROUPS all groups current user belongs to | |
$# number of positional params $OPTARG getopt last option value | |
$? exit status $OPTIND getopt last option index | |
$- current option flag $OPTERR getopt error message | |
$$ PID of shell or shell script | |
$! PID of most recent async cmd | |
$0 name of shell script. | |
$_ absolute pathname | |
Compound Commands | |
================= | |
Looping Constructs Conditional Constructus | |
------------------ ----------------------- | |
until ...; do ...; done if ...; then ...; [elif ...; then ...;] fi | |
while ...; do ...; done case ... in | |
for ...; do ...; done ...) ... | |
for ... [in ...]; do ...; done ...) ... | |
for (( expr1; expr2; expr3 )); do ...; done esac | |
select ... [in ...]; do ...; done | |
Grouping Commands | |
----------------- | |
() execute enclosed commands | |
in a subshell | |
{} execute enclosed commands | |
in current shell. needs a ";" | |
to terminate command. | |
References | |
---------- | |
http://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html | |
http://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html | |
http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html | |
http://www.gnu.org/software/bash/manual/html_node/Compound-Commands.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment