Need help with find its action


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with find its action
# 1  
Old 11-09-2009
Need help with find its action

I am writing a shell script that takes at least 2 arguments. The first is an octal representation of file permissions, the second is a command that is executed on all the files found with that permission.

Code:
#!/bin/sh
find . -perm $1 -exec $2 $3 $4 {} \;

invoked: ./script.sh 543 ls -la

what I have now works alright, but it assumes that there are no more than 2 options with the command. Also on the system I'm using it ignores the $3 and $4 if not further arguments were passed, but this is poor style and I'm guessing some systems may get messed up.

I tried
Code:
#!/bin/sh
shift
find . -perm shift -exec
while [$# gt 0]
do
    shift
end
{} \;

but this didn't work.

Is my question clear or should I clarify?
Thanks for the help.
# 2  
Old 11-09-2009
Try
Code:
#!/bin/sh
var1="$1"
shift
find . -perm "$var1" -exec "$@" {} \;

# 3  
Old 11-10-2009
thanks, it works
why do you put the variables in double quotes?
# 4  
Old 11-10-2009
In order to avoid possible future trouble with parameters that contain non-alphanumerical characters. Perhaps some of the double quotes are superfluous in this case.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check load and action

Hey everyone can you check this script logic ? it has to restart webservice if found server load is higher than X, also i have put it in crontab to run every one minute #!/bin/bash loadavg=$(uptime | awk -F "." '{ print $1 }' | awk -F ":" '{ print $5 }') if ; then pkill -9 httpd service... (7 Replies)
Discussion started by: nimafire
7 Replies

2. Shell Programming and Scripting

multiple action!

lets explain it easy by showing the initial file and desired file: I've a file such this that contains: initial_file: 31/12/2011 23:46:08 38.6762 43.689 14.16 Ml 3.1 ... (1 Reply)
Discussion started by: oreka18
1 Replies

3. Shell Programming and Scripting

split an action in groups

Hi all, I need some help with a script I would like to amend.Let's say it's a simple script like the one below controls=`grep line /etc/file |grep -v "^#"| awk -F":" '{print $4}'` for cc in $controls do echo $cc sleep 2 done cc variable holds a list of 40 numbers.... (2 Replies)
Discussion started by: geovas
2 Replies

4. Shell Programming and Scripting

Math action in ksh

Hello, I want to do div action in ksh and get the full result(with leftover). i.e. 4/3=1.33 and not 4/3=1 (4 Replies)
Discussion started by: LiorAmitai
4 Replies

5. Shell Programming and Scripting

same action in then as in else: explanation?

in /etc/init.d/networking of an ubuntu computer, I found this code: if ifdown -a --exclude=lo; then log_action_end_msg $? else log_action_end_msg $? fi Shouldn't it be replace by ifdown -a --exclude=lo ... (0 Replies)
Discussion started by: raphinou
0 Replies

6. Shell Programming and Scripting

how can i do some action when 'ctrl+d' is pressed

hi Gurus, please why is this happening: when i run this: #!/bin/bash declare -a name declare -a ph declare -a eid r=0; c=1; i=1; n=; echo " name phone email_id" while : do #if ; then #break; #else echo -n "field $i:"; read name ph eid; let "i++"; ... (5 Replies)
Discussion started by: tprayush
5 Replies

7. Shell Programming and Scripting

action command

Hi.. When i refered the script /etc/rc.sysinit... i found the "action commands" like But this is not working in my shells.. the following error is coming... Please anybody help Thanks in advance esham (5 Replies)
Discussion started by: esham
5 Replies
Login or Register to Ask a Question