I managed to cut and paste your code into a file, and it worked correctly. if you execute it as follows:
Your file "file.sh":
#!/bin/bash # june 2011 if [ $# -lt 3 -o $# -gt 3 ]; then echo "Error... Usage: $0 host database username" exit 0 fi
Team:
$ ./file.sh arg1 arg2 arg3
Note that "file.sh" must be executed:
$ chmod +x file.sh
You can get this b / c error from how you make input (with pipe, carrots, etc.). You can also try splitting the condition into two:
if [ $# -lt 3 ] || [ $# -gt 3 ]; then echo "Error... Usage: $0 host database username" exit 0 fi
Or, since you are using bash , you can use the built-in syntax:
if [[ $# -lt 3 || $# -gt 3 ]]; then echo "Error... Usage: $0 host database username" exit 0 fi
And finally, you could, of course, just check to see if 3 arguments were provided (clean, supports POSIX shell compatibility):
if [ $# -ne 3 ]; then echo "Error... Usage: $0 host database username" exit 0 fi
aaronstacy Jun 16 2018-11-11T00: 00Z
source share