hello all newbie here :D
i am working on a project right now which involves a script that handles a *.dat file.The script runs under specific commands inputed by user
my problem is that i cant figure out how to "grab" the arguments from the command to "import" them to the script
here are some examples from the specific commands :
./tool.sh -f <file>
./tool.sh -f <file> -id <id>
./tool.sh --born-since <dateA> --born-until <dateB> -f <file>
where tool.sh is the scripts name, <file>
is the *.dat
file, <date>
is just a date in this format YYYY-MM-DD
so as you can see there are both shortwords and longwords. I know that the getopts command is tricky to handle the long ones. How can i handle all of them using a "single" piece of code?
edit: i need to use the arguments and the conditional expressions for a case using the "if"
so could i just do :
#!/bin/bash
getopts f a
if [ $1 == "something" && $2 == "something2" && $a == "f" ]; then
....
elif [ $1 == "something3" && $2 == "something4" && $a == "f" ]
....
else
....
fi
would that be correct?