The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
"mt erase" command does not work krishan Filesystems, Disks and Memory 2 03-19-2009 10:00 PM
"find command" to find the files in the current directories but not in the "subdir" swamymns Shell Programming and Scripting 9 07-22-2008 11:23 AM
passing a list of dynamic names to a "PS" command in shell script? sachin.tendulka Shell Programming and Scripting 3 11-21-2007 04:18 AM
Passing argument to "at" command nibl Shell Programming and Scripting 2 07-22-2006 11:36 PM
"man date" command does not work aptit UNIX for Dummies Questions & Answers 1 02-15-2002 08:58 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-15-2006
unxuser unxuser is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 4
How to get Find command work with a variable passing "*" value?

Hi guy,

I have a problem to pass a variable containing '*' value to FIND command.
below is the script. It doesn't work by submit below command:

rmf.sh name '*.txt'
or
rmf.sh name *.txt

I've tried either optn="-name '$2'" or optn="-name $2"., and there is no luck.

Code:
### (script name = rmf.sh) 
 #!/bin/ksh -x
 #$1 - name of option
 #$2 - pattern of filename or age of file

if [ "$1" == "name" ]; then
    optn="-name '$2'"
else
    optn="-mtime +$2"
fi
find . -type f $optn -ls
Thanks in advance
  #2 (permalink)  
Old 08-15-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
EDIT---
Updated to take care of "*", here is the code and sample use of the script:
Code:
admin@unix1:/home/admin/scripts$./find1 name "*.txt"
./test1/a.txt
./a.txt
./b.txt
Code:
admin@unix1:/home/admin/scripts$cat find1
### (script name = rmf.sh)
 #!/bin/ksh -x
 #$1 - name of option
 #$2 - pattern of filename or age of file
tmp=`echo "$2" | sed 's/\"//'`
if [ "$1" == "name" ]; then
    optn="-name"
else
    optn="-mtime"
fi
find . -type f $optn "$tmp" -print
Regards,
Tayyab

Last edited by tayyabq8; 08-15-2006 at 10:32 AM.. Reason: Updated to take "*" as argument
  #3 (permalink)  
Old 08-15-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
pls read the Rules and dont' cross-post.

Threads merged!

Last edited by vgersh99; 08-15-2006 at 11:07 AM..
  #4 (permalink)  
Old 08-15-2006
unxuser unxuser is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 4
re

Thanks Shereenmotor,

find . -type f $optn "$tmp" doesn't work for me.

find . -type f $optn "$2" works fine.

I expect that $optn can pass more combined options (ie. -name "*.txt" -mtime +300) to FIND command.
  #5 (permalink)  
Old 08-16-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Yes you are right "$2" should work also, because I was under the impression that $2 will have the value "*.txt" ie with quotes and it can create problem, therefore I stored the value of $2 in tmp variable after removing any quotes, but in fact tmp is not required here at all, you can remove that.
Quote:
I expect that $optn can pass more combined options (ie. -name "*.txt" -mtime +300) to FIND command.
I don't understand exactly what you are trying to do here with passing same parameters which you can pass directly to find in the same fashion? It is almost useless to write code for the same function which is already provided in the command, we can do many things with parameters and find command but can you pls explain what is your exact requirement and why you need it?

Regards,
Tayyab
  #6 (permalink)  
Old 08-16-2006
unxuser unxuser is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 4
To shereenmotor:

My idea is to create an utility in a shell script for the user removing their old files. The utility leads the user to select an option from the screen manu to remove the file based on the age of file, pattern of file name or both. So the use is able to enter the paramater values. In the script, a string of option for FIND command will be assembled and be passed to the command line. Thanks again.
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0