how do i pass a wild card as an argument
Category: UNIX-Unix Beginner
how do i pass a wild card as a variable
hi,
i would like to pass a wild card as part of an argument. but when i do it the script views the wild card as text.
example:
sfile=mg1a*
sort $sfile > $sfile.sorted
what i get is mg1a*.sorted
the problem is i am passed a series of files where the first few characters like "mg1a" are constant. the additional part of the file name is a date time stamp. i will never know the exact date time stamp. i need to do a search for mg1a* which will find me one file. how can i write my script so the variable $sfile will know that the "*" in mg1a* is a wild card not text?
i know i can write code to run "ls" on a directory and get all file names then write a loop or do statement to do my sort based upon that list regardless of the file name. but i have more files in the dir than i want to grab. i also know i can run the "ls" command output the file names in the dir to a file and grep for the part fo the file names i am looking for. i also think this can be done if i pput the whole comamnd ibut current design restricts me form going that path. it would require a whole re-write and i am trying to avoid that.
thank you.
quote:
originally posted by eja
hi,
i would like to pass a wild card as part of an argument. but when i do it the script views the wild card as text.
example:
sfile=mg1a*
sort $sfile > $sfile.sorted
what i get is mg1a*.sorted
the problem is i am passed a series of files where the first few characters like "mg1a" are constant. the additional part of the file name is a date time stamp. i will never know the exact date time stamp. i need to do a search for mg1a* which will find me one file. how can i write my script so the variable $sfile will know that the "*" in mg1a* is a wild card not text?
i know i can write code to run "ls" on a directory and get all file names then write a loop or do statement to do my sort based upon that list regardless of the file name. but i have more files in the dir than i want to grab. i also know i can run the "ls" command output the file names in the dir to a file and grep for the part fo the file names i am looking for. i also think this can be done if i pput the whole comamnd ibut current design restricts me form going that path. it would require a whole re-write and i am trying to avoid that.
thank you.
try changing (ksh)
sfile='mg1a*'
sort $sfile > $sfile.sorted
be sure and use single quotes - it will not expand out the wildcard at the assignment line.
works great. thanks. i tried everthing bu. feel dumb now. i tried "" and `` did not think of single qoutes
