bash: working with directories

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

Sample code: check if directory exists, if not, create it. Check if the directory is writable.

if test ! -d "$MYDIR"
then
  mkdir "$MYDIR"
elif test ! -w "$MYDIR"
then
  echo "$MYDIR exists but is not writable."
  exit 3
fi