Bash

Bash

Bash / sh

#!/bin/sh

#!/bin/bash

Cheatsheet

If

if [ "$INTERFACE" != "pppoe-wan" ]
then
        exit
fi
  • Operator: =, !=

Switch

# This script does a very simple test for checking disk space.

space=`df -h | awk '{print $5}' | grep % | grep -v Use | sort -n | tail -1 | cut -d "%" -f1 -`

case $space in
[1-6]*)
  Message="All is quiet."
  ;;
[7-8]*)
  Message="Start thinking about cleaning out some stuff.  There's a partition that is $space % full."
  ;;
9[1-8])
  Message="Better hurry with that new disk...  One partition is $space % full."
  ;;
99)
  Message="I'm drowning here!  There's a partition at $space %!"
  ;;
*)
  Message="I seem to be running with an nonexistent amount of disk space..."
  ;;
esac

Tips

Output binary data

# Only work in bash. DO NOT work in sh!
echo -n -e '\x01\x02' > file

Last update: 2019-08-28 07:39:28 UTC