#!/bin/sh -u # $0 (no arguments) # Test numeric arguments containing blanks. # # Most versions of the shell accept blanks in numeric arguments to test, # some versions do not. Bash shells keep their version number in # the variable $BASH_VERSION: # # $ echo $BASH_VERSION # 2.04.12(1)-release # # I've found that version 2 of the bash shell doesn't allow blanks. # (Version 1 does!) # # If you use a shell that doesn't allow blanks: # # Why do the first three tests generate error messages? # Why do the second three tests work correctly? # # This script uses conditional command execution via "&&". # The command to the right of "&&" only executes if the command to the # left of the "&&" exits with a zero (good) return status. # # Try running this script under "sh -x" to see the shell processing. # # -IAN! idallen@ncf.ca June 2001 x=" 123 " y=" 456 " # If your shell doesn't like blanks, these three fail using "$x" and "$y": # if [ "$x" -lt "$y" ]; then echo "You never see this. Why?" fi test "$x" -lt "$y" && echo "You never see this. Why?" [ "$x" -lt "$y" ] && echo "You never see this. Why?" # These three work in all shells using $x and $y: # if [ $x -lt $y ]; then echo "You do see this. Why?" fi test $x -lt $y && echo "You do see this. Why?" [ $x -lt $y ] && echo "You do see this. Why?"