Skip to content

Instantly share code, notes, and snippets.

@edwelker
Last active December 14, 2015 14:48
Show Gist options
  • Save edwelker/5103096 to your computer and use it in GitHub Desktop.
Save edwelker/5103096 to your computer and use it in GitHub Desktop.
Bash Notes

Bash notes

bash -n : test syntax without running the script shopt -s extglob : turns on extra glob features of the shell (for regexp tests) set -o noclobber - prevents overwriting files

General

  • {} : groups a series of commands.
  • () : groups a series of commands and executes them in a subshell
  • $() - the newer syntax for ``
  • $(( )) : lets you do arithmatic inside
  • | - will overwrite a file even with noclobber on

  • <</EOF - prevents evaluating variables
  • read -p "your prompt" variable
  • $? - the exit status of the last command run
  • cmd1 && cmd2 && cmd3 - will shortcircuit if the previous command fails
  • nohup - ignores hangup from closing a bash shell (for running headless cmds)
  • env is a subset of set
  • let y+=3 : won't echo result

Params being passed

  • ${1} - first arg
  • $* - all arguments
  • $@ - all args quoted?
  • ${#} - the number of args

grep

  • grep -l : prints filenames only
  • grep -v : the stuff to ignore (grep "whatever" file | grep -v "but ignore this pattern")

comparisons

testing numbers

[ 4 -lt 5 -a 6 -eq 6 ]

  • comparisons: -lt, -eq, -ne, -ge, etc.
  • booleans: -a (and), -o (or)

testing strings

[ '4' == '4' -a '6' != '5' ]

  • comparisons: ==, !=, >, <=, etc.

[[ ]] - more powerful comparison, not supported in older shells

find

  • find --follow : will follow simlinks
  • find --iname : case insensitive filenames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment