Check if running in interactive session

if tty -s; then
  echo "Running in interactive mode"
else
  echo "Running as a script"
fi

For example, to show a prompt for password input vs. reading from some file/stdin.

String manipulation

Trim leading and trailing whitespaces from lines

awk '{$1=$1};1'

Remove extraneous spaces

echo "  hello   world   " | xargs