LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-09-2012, 12:12 AM   #1
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 835

Rep: Reputation: 165Reputation: 165
temp path edit for find execdir in script or on command line


My path includes '.', and find with execdir complains about it. I get a message like this:

Code:
find: The current directory is included in the PATH environment variable, which is insecure in combination with the -execdir action of find.  Please remove the current directory from your $PATH (that is, remove "." or leading or trailing colons)
So what I'd like to know is if there is a way I can temporarily edit the path used by the find command to exclude the current directory '.', either as a command line edit, or in a script, without having to manually remove '.', execute find, then add '.' back to my path in three discrete actions.

It would be nice if find would just do this itself. But since I'm not a developer for find, I can't justifiably complain about it.

Last edited by Z038; 03-09-2012 at 12:15 AM.
 
Old 03-09-2012, 02:14 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Try this:
Code:
# dot at beginning of PATH
$ PATH=${PATH#.:} find . -name "xyz" -execdir ls {} \;

# dot at end of PATH[/i]
$ PATH=${PATH%:.} find . -name "xyz" -execdir ls {} \;
The above uses bash internals to strip the .: (or :.) part from your PATH setting. This is temporary in this case. The changed variable (PATH) is given to find.

Hope this helps.
 
1 members found this post helpful.
Old 03-10-2012, 12:33 AM   #3
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 835

Original Poster
Rep: Reputation: 165Reputation: 165
Thank you very much drunna. This is the sort of thing I had in mind, but I had no idea how to approach it.

Unfortunately, my '.' is in the middle of my path variable. But this at least gives me something to investigate.

Last edited by Z038; 03-10-2012 at 12:34 AM.
 
Old 03-10-2012, 01:03 AM   #4
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 835

Original Poster
Rep: Reputation: 165Reputation: 165
I found this reference about string manipulation in bash. http://tldp.org/LDP/abs/html/string-manipulation.html I'm hoping this will lead to a solution.
 
Old 03-10-2012, 01:12 AM   #5
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 835

Original Poster
Rep: Reputation: 165Reputation: 165
Got it! This does the trick. Again, thanks to you drunna.

Code:
PATH=${PATH/.:/} find . -name "xyz" -execdir ls {} \;
 
Old 03-10-2012, 01:26 AM   #6
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 835

Original Poster
Rep: Reputation: 165Reputation: 165
Ok, maybe I was premature in marking this solved. It's not exactly working. So I marked it unsolved again. But I am close.

This is actually what I'm trying to do, but I'm still getting an error.

Code:
#!/bin/bash
PATH=${PATH/.:/} find subdir -type f -execdir chmod go-rwx {} \;
PATH=${PATH/.:/} find subdir -type d -execdir chmod go-rwx {} \;
I just issue this from the command line:

Code:
echo PATH=${PATH/.:/}
the PATH shows up without the ".:" in the middle. But similar syntax in the bash script at the top doesn't seem to work.

Last edited by Z038; 03-10-2012 at 01:29 AM.
 
Old 03-10-2012, 04:18 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Removing the . (:. or .: to be more precise) works, that doesn't seem to be the problem.

If I assume that subdir in the find command is an actual directory and present in the directory you execute the script from. Also works:
Code:
~/Temp $ ls -l *
-rwxr-x--- 1 druuna internet  156 Mar 10 10:06 foo.sh

subdir:
total 8
drwxrwxr-x 2 druuna internet 4096 Mar 10 10:05 Dir1
-rwxrwxr-x 1 druuna internet    0 Mar 10 10:05 file1

~/Temp $ cat foo.sh
#!/bin/bash
PATH=${PATH/.:/} find subdir -type f -execdir chmod go-rwx {} \;
PATH=${PATH/.:/} find subdir -type d -execdir chmod go-rwx {} \;

~/Temp $ ./foo.sh

~/Temp $ ls -l *
-rwxr-x--- 1 druuna internet  156 Mar 10 10:06 foo.sh

subdir:
total 8
drwx------ 2 druuna internet 4096 Mar 10 10:05 Dir1
-rwx------ 1 druuna internet    0 Mar 10 10:05 file1
If I run this from any other directory (not containing a subdir directory, I'll see an error (as expected):
Code:
find: subdir: No such file or directory
find: subdir: No such file or directory
Can you post the full script and the actual error you are getting?
 
Old 03-10-2012, 11:35 AM   #8
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 835

Original Poster
Rep: Reputation: 165Reputation: 165
druuna, the problem was that I had '.' in my path twice. It was in the middle and at the end, like this:

Code:
me@here:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib/java/bin:/usr/lib/java/jre/bin:/usr/lib/java/bin:.:/usr/lib/kde4/libexec:/usr/lib/qt/bin:/usr/share/texmf/bin:.
Here is the final script, which worked once I put both edits in it:

Code:
#!/bin/bash
PATH=${PATH/.:/} PATH=${PATH%:.} find docs -type f -execdir chmod go-rwx {} \;
PATH=${PATH/.:/} PATH=${PATH%:.} find docs -type d -execdir chmod go-rwx {} \;
Before I put in the second edit to remove the '.' at the end, it was just giving me the normal error you get when you have '.' in your path.

Code:
me@here:~$ ./fixdir.sh
find: The current directory is included in the PATH environment variable, which is insecure in combination 
with the -execdir action of find.  Please remove the current directory from your $PATH (that is, remove "." 
or leading or trailing colons)
find: The current directory is included in the PATH environment variable, which is insecure in combination 
with the -execdir action of find.  Please remove the current directory from your $PATH (that is, remove "." 
or leading or trailing colons)
Last night I just didn't see that I had '.' in my path twice, so it was really confounding me. But adding both of the string edits to my PATH variable took care of it.

Thank you again for your help.
 
Old 03-10-2012, 12:22 PM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
You're welcome
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trying to edit a file via Command line or script seefor Linux - General 4 10-21-2008 01:39 PM
find with execdir seems to ignore umask settings theking2 Linux - Security 2 04-02-2007 04:34 AM
command line edit -- global find/replace on text file w/o going into vi car182 Linux - Newbie 4 05-25-2006 06:42 PM
edit wav files via command line in a script legolin Linux - Software 4 12-21-2005 11:09 AM
Can't find edit grub.conf when im in command line. izac5 Linux - Newbie 7 11-16-2004 05:24 PM


All times are GMT -5. The time now is 10:21 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration