bash script tricks

May 13, 02:24 PM

  • Use this shebang to start your script, which ensures you are not using undefined variables:
    #!/bin/bash -u
    From the bash man pages: “-u: Treat unset variables as an error when performing parameter expansion. If expansion is attempted on an unset variable, the shell prints an error message, and, if not interactive, exits with a non-zero status.”
  • Use tar dash-z to ungzip and untar a file in one command.
    Example:
    tar -xzvf dada-$VERSION.tar.gz
  • Instead of moving the original to Config.pm, copy Config.pm to Config.pm.original. Then use sed -i to edit Config.pm in place.
  • to echo in a password (or any value):
     echo myPasswordValue | sudo --stdin  systemctl stop  firewalld.service ;

bash reference card – 2010-06-17
good comparison of IF statement syntax – 2010-06-17

Mark Edwards

,

---

Commenting is closed for this article.

---