Skip to content

Shell

  • $PS1: prompt
  • $HOME: base directory
  • $IFS: separator
  • $0: name of the script
  • $1, $2: arguments
  • $*: list of arguments - truncated with first char of $IFS
  • $@: list of arguments - as separated args
  • $#: number of arguments
  • $?: last return code

man bash can explain a lot

#!/bin/sh
x="hello world"
# a variable without quote can be two separate arguments
printf '%s\n' $x
# hello
# world
# a variable with quote will be one argument (exception exists for $@)
printf '%s\n' "$x"
# hello world
# the $IFS char will be replaced by space
# you can also change the IFS temporarly
IFS='w'
printf '%s\n' $x
# hello
# orld
# note the space after hello and the missing 'w'
printf '%s\n' "$x"
# hello world
IFS=' ' # reset the IFS
Terminal window
test -f myfile # return 1
touch myfile
test -f myfile # return 0
# You can also use the test binary with the '[' binary - it's the same form
# but you need a closing ']'
[ -f myfile ]