LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-01-2010, 10:35 AM   #1
mszabo
LQ Newbie
 
Registered: May 2010
Location: Hungary
Distribution: debian lenny
Posts: 2

Rep: Reputation: 0
Using find with variables in shell script


Hi,
I would like to know if find 4.4.0-2 can be used in a shell script to set the search location via a variable.
Can someone help, please?
I need to determine which files can be executed by anyone on paths given by $PATH.
I have found that:
find [location] -type f -perm /u=x,g=x,o=g
would be a good solution to turn to.
Now, I want to tokenize $PATH and supply each path via a variable [location]. Is it possible?
Marton
 
Old 05-01-2010, 11:53 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Something like this maybe (one-liner):

for THIS_DIR in ${PATH//:/ }; do find ${THIS_DIR} -type f -perm /u=x,g=x,o=g; done

This will feed find all the path's that are inside the $PATH variable. If for example PATH=/bin:/usr/bin, find will be given /bin and then /usr/bin.

Hope this helps.
 
Old 05-01-2010, 01:36 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Actually the loop it's not necessary, since find can manage multiple paths at once:
Code:
find ${PATH//:/ } -type f -perm /u=x,g=x,o=g
 
Old 05-01-2010, 02:51 PM   #4
mszabo
LQ Newbie
 
Registered: May 2010
Location: Hungary
Distribution: debian lenny
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
Actually the loop it's not necessary, since find can manage multiple paths at once:
Code:
find ${PATH//:/ } -type f -perm /u=x,g=x,o=g
Thanks, colucix! This worked!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Variables in SHELL SCRIPT rahulruns Programming 1 11-12-2009 12:52 AM
Shell script variables Fredde87 Linux - Newbie 13 11-01-2006 03:35 AM
shell script variables Gary_Menegon Programming 1 10-02-2006 09:28 AM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 04:32 AM
Why?? can not use variables with shell script Bassam Linux - General 9 01-27-2004 07:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration