Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to look for certain files

Status
Not open for further replies.

mpezeur

MIS
Nov 7, 2002
123
US
I have a script that looks in a particular directory for filenames that match a particular naming criteria. When I use that criteria using an ls command, it displays the correct output, but when I use the same exact substitution criteria with a variable, I am told that the same files, found from command line, do not exist.

PRSQR=pktpr4+(2[6,8-9]|3[0,5,9]|4[1,4]|5[4,9]|6[0,3,6-8]|7[0-3,6]|9[1-3,7])*

will look for any files that begin with pktpr4, followed by one of the criteria, and could end with anything.

when I execute:

ls pktpr4+(2[6,8-9] ... 9[1-3,7])* as you see above, it finds all files with this naming structure.

When I use variable substitution, is doesn't seem to work. I think it's related to the + that I have in the search criteria.

I need to script this, using variable substitution, for a script that will move these files to a particular directory in another filesystem.
 
My gut tells me that the * at the end is not being interpreted the way you want when setting/using the variable. Try putting the assignment value in quotes. When you run it with ls at the command line the shell is interpreting the * the way you want.
 
yes, when I use the criteria above in the ls statement, and include * at the end, it's fine. That's why I'm assuming it's having a problem interpreting the + sign when assigned to a variable.
 
Can you set PRSQR without the * and then use

ls $PRSQR*
 
yes, I tried that, and I receive the error

ksh cannot find file pktpr4+(2[6,8-9]| ...
 
You could try this... it works, but not sure if it will work in your context


PRSQR=`ls pktpr4+(2[6,8-9]|3[0,5,9]|4[1,4]|5[4,9]|6[0,3,6-8]|7[0-3,6]|9[1-3,7])*`

echo $PRSQR


The first line executes the command and stores the output in the variable PRSQR. The second line will display the output.

I hope that helps...



LHLTech

IBM Certified ATE
 
well, that does work. My problem is that my main script has a large CASE statement that identifies each file in the directory, and uses each variable, like PRSQR, as the criteria. The other variables work in this case statement, because they aren't as complex. In this case, the PRSQR variable would be almost like an array, that would have to say 'if current file is in array $PRSQR then move to new directory', and therefore wouldn't work in my current CASE statement.

I guess there is no other way to have this criteria work other than to use VARIABLE=`ls pktpr4+ ...` ,correct ?
 
did you try single-quotes or double-quotes? single-quotes will avoid any shell interpretation before storing into the variable. try print $PRSQR to see if it contains the text you expect it should.

using backticks will store the command output into the variable, which may be what you want.

IBM Certified -- AIX 4.3 Obfuscation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top