LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 06-03-2010, 01:23 AM   #16
Andre1234567
LQ Newbie
 
Registered: Jun 2010
Posts: 8

Original Poster
Rep: Reputation: 0

Hi,
this works, but I think it I should not change the settings on the production environment. Do you have an other idea?

Kind Regards
Andre

Code:
Directory="-lname *"
set -f                  # Turn off bash filename expansion
for i in $(find . ${Directory});do
echo $i
done
set +f                  # Turn on bash filename expansion
[/QUOTE]
 
Old 06-03-2010, 02:20 AM   #17
bdt-rob
LQ Newbie
 
Registered: Jun 2009
Location: Cambridge, England
Distribution: Gentoo, Arch, (xandross), (Slackware)
Posts: 16

Rep: Reputation: 2
You can't take the quotes out entirely, Alunduil, as the shell will then expand the "*" in the wrong way.

The use of $() is irrelevant, MTK358, so just stop harping on about it.

@Andre : The reason your modification of my advice didn't work is that by quoting the "-lname" in with the "*" you have merged them into a single entity. You NEED the "*" to be a single, quoted entity (not single-quoted, though) so that the shell doesn't expand it (and thus leaves a wild card for find to work with) but you MUST NOT merge it with the "predicate" (the rule "-lname") otherwise the expression is not one of the valid rules.

Using the "set -f" to avoid wildcard expansion is acceptable, but like you I find it ugly. I would strongly recommend NOT including "-lname" in your $Directory variable, as it's not part of the pattern anyway so logically it's misleading to have it there.

Code:
Directory="*"
for i in $(find . -lname "${Directory}");do
echo $i
done

Last edited by bdt-rob; 06-03-2010 at 02:32 AM.
 
1 members found this post helpful.
Old 06-03-2010, 07:24 AM   #18
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by bdt-rob View Post
The use of $() is irrelevant, MTK358, so just stop harping on about it.
I know it won't fix his script, but it's much better practice than backticks.
 
Old 06-03-2010, 07:53 AM   #19
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by bdt-rob View Post
You'll note I've reverted to back-ticks - they're perfectly good enough for this and rweaver's objection is an irrelevant red herring.
rweaver did not object; he correctly pointed out that "`` has been depreciated". The reasons are set out here.
 
Old 06-03-2010, 07:54 AM   #20
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by bdt-rob View Post
Code:
Directory="*"
for i in $(find . -lname "${Directory}");do
echo $i
done
The { and } are not necessary; they are not wrong.
 
Old 06-04-2010, 03:08 AM   #21
Andre1234567
LQ Newbie
 
Registered: Jun 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Hi bdt-rob,
your solution worked fine. thanks a lot.

Kind Regards from Munich.
Andre


Quote:
Originally Posted by bdt-rob View Post
You can't take the quotes out entirely, Alunduil, as the shell will then expand the "*" in the wrong way.

The use of $() is irrelevant, MTK358, so just stop harping on about it.

@Andre : The reason your modification of my advice didn't work is that by quoting the "-lname" in with the "*" you have merged them into a single entity. You NEED the "*" to be a single, quoted entity (not single-quoted, though) so that the shell doesn't expand it (and thus leaves a wild card for find to work with) but you MUST NOT merge it with the "predicate" (the rule "-lname") otherwise the expression is not one of the valid rules.

Using the "set -f" to avoid wildcard expansion is acceptable, but like you I find it ugly. I would strongly recommend NOT including "-lname" in your $Directory variable, as it's not part of the pattern anyway so logically it's misleading to have it there.

Code:
Directory="*"
for i in $(find . -lname "${Directory}");do
echo $i
done
 
  


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
VMWare problems in Ubuntu 8.04 (Cant Find it??) oversword Linux - Software 4 05-02-2008 10:40 AM
problems using find Humbro Linux - Newbie 3 12-07-2007 08:13 AM
Problems to execute the FIND command hpinto Solaris / OpenSolaris 2 03-28-2006 06:56 PM
gcj problems 'cannot find -lz' zeppelin147 Linux - Software 0 11-17-2005 11:13 AM
C program that takes input "FName|LName" and outputs to std out its_godzilla Programming 2 01-18-2005 10:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:13 PM.

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