I have a script which fires a command based on certain parameters. I am posting the code below..
The options needs be given such that
-u option goes along with -d and -s, -f goes with -d and -t goes with -s and -d.
1) How do I ensure that user misses any of the option then he should be prompted . Is it simple if then else where I check the length of string of all these options.
USAGE="Usage: `basename $0` [-s schemaname] [-d databasename] [-u username] -f -t -h"
while getopts :s:d:u:fth params
do
case $params in
You could do it a couple ways, one - by adding a checksum count to each case. At the end of the getsopts statement and before any other code is executed, check to see if the checksum value is what is expected. If you dont like this approach, take the easy way and evaluate $#. $# holds a count of the number of command line arguments passed to the script.
I think I got it now.
If i provide scriptname -s schema -u user -d database, $# evaluates to 6 based on no of options and its values. (-s schema) 2, (-u user) 2 and (d database ) 2.
So if it is -d database -f it evaluates to 3 (-d database)2 and (-f) 1.
If he specifies -d database and -t ( That too evaluates to 3) .
How do i check if he has specified -t or -f then ?