In this example I want it to know if $@ contains two words/symbols “load” and “/”
for one word/symbol this works
case "$@" in */*)
;;
echo "going to do stuff"
*)
echo "will do something else"
;;
esac
or
string='My string';
if [[ "$string" == *My* ]]
then
echo "It's there!";
fi
But if two words/symbols appear at random places I cant figure out how to do it.
Update:
The input will the module command. In this case I want to know if it is the module load with or without / that indicate version. the command will look like this
1) module load appname/1.1.1 or
2) module load appname
3) module (not load) (list, avail etc)
It is number 1 I am interested in for now.
3 will in some cases be variation of 1.
2 will be run as is but will include a message to the user
Something like this is possible:
if [[ ${@} =~ .*/.* && ${@} =~ ((^)|([ ]))load(($)|([ ])) ]] then echo both fi-or-
if LOAD=0 && SLASH=0 && \ for ARG in ${@}; do if [ "${ARG#*/}" != "${ARG}" ]; then SLASH=1; fi if [ "${ARG}" = "load" ]; then LOAD=1; fi done && [ "${LOAD}${SLASH}" = "11" ]; then echo both fi-or-
function loadslash() { LOAD=0 && SLASH=0 for ARG in ${@}; do if [ "${ARG#*/}" != "${ARG}" ]; then SLASH=1; fi if [ "${ARG}" = "load" ]; then LOAD=1; fi done test "${LOAD}${SLASH}" = "11" } if loadslash ${@} then echo both fi