The code below is just a rough outline of what I am trying to do. Don't worry about what the code is doing after each case is evaluated.
My question is that in the case *','* )
I am trying to recognize a dynamic pattern of files separated by commas.
Ex: getfile.sh -fileextension file1,file2,file3,file4 would be my input. How would i go about recognizing that the input from $2(this is equal to var2) follows the *','*
pattern where * represents the file?
if [ $flag -eq 1 ]; then
case $var2 in
#lists files if option is selected
list | l | LIST | L | ls | LS) do stuff here
all | a | ALL | A) do stuff here
*','* ) do stuff here
* ) do stuff here
esac
fi
I should add that the program is supposed to list a set of files based on their extension and then allow the user to either get all those files, or select mutliple (or a single) file. Because i will not know what the user is going to input i'm trying to match a pattern instead of a static input.
So here is what my new code looks like and is much closer to what i'm trying to accomplish:
Let's jsut concentrate on the case so as to not get confused.
case $var2 in
#lists files if option is selected
list | l | LIST | L | ls | LS) ls -1 $DIRECTORY*$extension
exit
;;
#copy all files in the directory
all | a | ALL | A)
echo ">Cleaning temp dir"
allcheck=1
cleantemp
copy
zip
exit
;;
[0-9][0-9a-zA-Z] | [0-9]','[0-9a-zA-Z]) echo "this is valid input"
exit
;;
* )
echo ">>Bad argument"
#help
exit 1
#fi
esac
This is the pattern i'm trying to match
[0-9]','[0-9a-zA-Z]
I figured it out after finding a link that gave me a clue: How do I test if a variable is a number in Bash?
Anyways here's what i ended up with:
case $var2 in
#lists files if option is selected
list | l | LIST | L | ls | LS) ls -1 $DIRECTORY*$extension
exit
;;
#copy all files in the directory
all | a | ALL | A)
echo ">Cleaning temp dir"
allcheck=1
cleantemp
copy
zip
exit
;;
[0-9][0-9a-zA-Z] | [0-9][0-9a-zA-Z],[0-9][0-9a-zA-Z],*) echo "this is valid input"
exit
;;
* )
echo ">>Bad argument"
#help
exit 1
#fi
esac
This test is for input such as 56 or 5A [0-9][0-9a-zA-Z]
This test is for input that is separated by a comma such as what i was tryign to accomplish. [0-9][0-9a-zA-Z],[0-9][0-9a-zA-Z],*
(I will still have to make sure invalid characters are not entered, however, it really cut down on the work i have to do now.)
Thanks for trying to help 'the other guy'.