I have a script which you can pass test suites as parameters to:
$ bash-specs a.suite b.suite
If the user doesn’t supply any test suites, all the test suites in the current folder shall be executed. This is how I do this currently:
local suites
if (($# > 0)); then
suites=$@
else
suites=*.suite
fi
This is an okay solution but I have a feeling there is a more elegant way. I basically look for some way to do a conditional assignment or setting a default value if no parameters are given.
I’d do this:
Now you have the filenames in $1, $2, etc. no matter whether the user specified them or let them default.
Some notes:
Your assignment to
suitesdoesn’t seem to result in anything useful; it’s not an array, so you get either a string with space-separated file names, or the unexpanded glob"*.suites". I’m guessing you somehow wind upevaling that later on, but that’s a bad idea – any spaces or funky characters in the file names will screw things up. I recommend looping over the arguments and handling them individually, or using an actual array.If you use something like my snippet above,
"$@"will expand to all the arguments, properly separated as if individually quoted. If you are going to be mucking with the arguments, you can save the original arguments in an array variable like so:And then retrieve the whole thing (again, properly separated) with
"${suites[@]}".