SH
Bash Cheatsheet
Bash shell scripting reference - variables, conditionals, loops, and the file/text commands used constantly.
Variables & basics
x="value"Set a variable (no spaces around =)
echo $xPrint a variable's value
$1, $2, ...Positional script arguments
$#Number of arguments passed
$?Exit code of the last command
Conditionals & loops
if [ "$x" = "y" ]; then ...; fiIf statement
for i in 1 2 3; do ...; doneFor loop
while [ condition ]; do ...; doneWhile loop
[ -f file ]Test if a file exists
[ -d dir ]Test if a directory exists
Common commands
ls -laList files, including hidden, with details
grep "pattern" fileSearch text in a file
find . -name "*.js"Find files by name pattern
chmod +x fileMake a file executable
cat file | grep x | wc -lPipe commands together