What I am trying to do is to pass arguments in my script such as
-h, -- help, -v, --version, -V, --Verbose, -o filename, --output=filename
-s searchphrase, --search=searchphrase, -f format, --format=format
Since I am a beginner in shell scripting I am not able to figure it out.....
No, you only need the one case statement; it reads all the parameters on the command line. Whatever was passed as the argument to -s will be in the variable $searchphrase.
That line doesn't use anything that has been passed on the command line (it also lacks a URL), so why do you need to parse anything to use it?
The case statement reads the options on the command line and sets variables based on what it finds.
If you entered test -s, you should get an error message (the code I posted isn't that sophiticated, however), because, according to what you posted before, it should have a searchphrase argument.
The revision allows non-option arguments to be included anywhere on the command line. When a non-option argument is encountered, it is added to the args variable. After the options have been parsed, those arguments are placed back into the positional parameters.
You gave a searchphrase argument in your initial post.
Do you have a command in the script that prints a value? If you do, it will. If you don't, it won't.
That depends on what your script does with it.
Putting something on the command line does nothing but make that argument available to the script. It's up to the script to do something (or nothing) with it.
You tell it to print the same thing whether the test succeeds or fails.
You don't use the command-line argument anywhere. You are always testing for /bin/bash.
case $1 in
-s) searchstring=$2 ;;
esac
if [ -s "$searchstring" ]
then
echo "file $searchstring exists"
else
echo "file $searchstring does not exist"
fi
Now, if I only run ./test in the terminal to create my .html files it shows the echo message "file does not exists" even though I didn't pass in the '-s' argument!