Pattern expansion problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern expansion problem
# 1  
Old 04-23-2007
Pattern expansion problem

All,
I have a shell script which executes the below command

find $1 -name $2 -print > ${Backup}/FileFind.txt

I have $2 sometimes coming with the below values.
.[a-z]*

When I go to the log after the execution of the script, .[a-z]* gets expanded to .developer.adm instead of searching for all the . files like .profile, .odbc etc. How do I comeover this issue?

Your help will be greatly appreciated.

Thanks.
# 2  
Old 04-23-2007
Try using double-quotes...
Code:
find "$1" -name "$2" -print > ${Backup}/FileFind.txt

# 3  
Old 04-24-2007
I tried using double quotes around the variables. But did not help Smilie
# 4  
Old 04-24-2007
That would suggest that $1 and $2 have already been expanded by the shell. Try adding double quotes when you call the script, e.g...
Code:
script.sh "$PARAM1" "$PARAM2"

# 5  
Old 04-24-2007
Quote:
Originally Posted by njoshi
All,
I have a shell script which executes the below command

find $1 -name $2 -print > ${Backup}/FileFind.txt

I have $2 sometimes coming with the below values.
.[a-z]*

When I go to the log after the execution of the script, .[a-z]* gets expanded to .developer.adm instead of searching for all the . files like .profile, .odbc etc. How do I comeover this issue?

Your help will be greatly appreciated.

Thanks.
i think if you have this:
Code:
# ./myscript.sh firstarg ".[a-z]*"

your second argument would have been expanded into the various files with that extension. you can try with this example in your script
Code:
#!/bin/bash
echo $2

so to overcome this if you want to use find, you may need generate a string to become "-name <> -o -name <> -o -name <> ..."...
that's what i think.
# 6  
Old 04-24-2007
The string need to be quoted both on the command line and in the script to be used as is.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use parameter expansion over a parameter expansion in bash.

Hello All, Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion. Let's say I have following variable. path="/var/talend/nat/cdc" Now to get only nat I could do following. path1="${path%/*}" path1="${path1##*/}" Here... (8 Replies)
Discussion started by: RavinderSingh13
8 Replies

2. Shell Programming and Scripting

Pattern matching problem

if i have to do pattern match for file name with digit alphanumeric value like this File_1234.csv File_12sd45rg.csv i am using this File_*.csv and File_*.csv for digit pattern match. when i am doing pattern match for the digit then both alphanumeric match and digit match is coming. ... (3 Replies)
Discussion started by: ramsavi
3 Replies

3. Shell Programming and Scripting

Pattern matching problem

Hi I need a bash script that can search through a text file for all lines starting with 71502FSC1206 on every line it finds starting with this I need to place a letter F at the 127 position on that line. Thanks Paul (6 Replies)
Discussion started by: firefox2k2
6 Replies

4. Shell Programming and Scripting

pattern matching problem

# cat email.txt | grep -i "To:" To: <test@example.com> # cat email.txt | grep -i "Subject" Subject: Test Subject: How are you. I need to print only test@example.com from To field need to eliminate "< & >" from To field and need to print entire subject after Subject: It should be #... (7 Replies)
Discussion started by: mirfan
7 Replies

5. Shell Programming and Scripting

Problem with tabs expansion

I have to create some fixed width files using UNIX. The data source is an Oracle SQL query. If I use straight SQL and spool to a file everything comes out as expected. Example Desired result (. indicate blank space): V278814831..................................1743049591.10N... (6 Replies)
Discussion started by: dortoh
6 Replies

6. Shell Programming and Scripting

Need to print the expansion of the found string (the expansion is beween two delimiters '-' , '||'

Hi , could anyone help me out with this problem. sample.txt has this content : u001- this is used for project1 || u002- this is used for p2|| not to be printed u003- this is used for project3 || u004- this is used for p4 || u005- this is used for project5 || u006- this is used for p6... (9 Replies)
Discussion started by: Balaji PK
9 Replies

7. Shell Programming and Scripting

Brace expansion problem in Bash

I have a script that takes an option for server pools to run the script against. The option is given as a comma separated list (ie, -p 201,204,301). I'm using eval and brace expansion to get those pool numbers into an array. It works fine unless only 1 pool number is given. Here's the code: ... (5 Replies)
Discussion started by: mglenney
5 Replies

8. Shell Programming and Scripting

Problem with search pattern

Can anyone help me in a scriptfor below example which has to find the string "System && Passcode 0" or "System && Failcode ??" If this searched string occurs consecutively 4 times it should provide output as error S.No : Program: Status 1. was : Passcode 1 2. System: Passcode 0... (1 Reply)
Discussion started by: gantagoru
1 Replies

9. Shell Programming and Scripting

pattern matching problem

FilesToBackup='*.track* *.xml *.vm* *.gz Trace* TRACE* "*core*" *.out fcif_data_* esi_error_* *.rollback *.sed R.* APStatus_* log* *.output* send_mail* downenv* check_env* intaspurge_db_* sqlnet.log *.rpt *.html *.csv "*TSC*"' and i am using it like this- echo Moving files from $(pwd): ... (2 Replies)
Discussion started by: namishtiwari
2 Replies

10. Shell Programming and Scripting

pattern matching problem

I have a file with the following contents; NEW 85174 MP081 /29OCT07 CNL 85986 MP098 /28OCT07 NEW 86014 MP098 /28OCT07 NEW 86051 MP097 /27OCT07 CNL 86084 MP097 /27OCT07 Now I have to retrieve all lines that start with NEW and where the next line starts with CNL and where the MP codes are... (8 Replies)
Discussion started by: rein
8 Replies
Login or Register to Ask a Question