Hello
I would like to write a bash shell script which will need user to supply one variable which is mandatory and some other optional variables. If mandatory variable is not supplied by user, the script will exit. If optional values are not supplied by user, hard-coded value (in the script) will be used.
Please help
You can continue your code/script followed by this below if statement.
#!/bin/bash
if [ $# -lt "1" ]; then
echo "Usage: $0 <something>"
exit 1;
fi
Both answers that you have already are useful. I would use a combination of if [ $# -lt "1" ]; then
and getopts
. You should start by writing a test script that will take the parameters that you want and print out the parameter passed in, specifically the optional parameters. Once you know that the script is handling the parameters correctly, then you can write the rest of the script.