Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You are asking find to locate all links that point to a file explicitly called '*'. I very much doubt you have any files called '*'. Why are you putting '*' in your script?
Okay...maybe let me describe my problem somehow else
I want to delete links using the following sh skript:
----------------------------------------------
mysearch="find . -lname '*'"
for i in `${mysearch}`; do
rm $i
done
----------------------------------------------
This skript does not delete the links.
If I replace the rm statement by a debug outoput and run the sh skript this also does not show me an output
----------------------------------------------
mysearch="find . -lname '*'"
for i in `${mysearch}`; do
echo found link $i
done
----------------------------------------------
but if I just enter the following command in the command line it shows me the links.
find . -lname '*'
What have I done wrong in my first script and second script, so the files are not displayed/deleted in the output?
Thanks
Kind Regards
Andre
Last edited by Andre1234567; 06-01-2010 at 03:52 PM.
When the shell expands stuff, it explicitly does not substitute variables within single quotes. Thus your script is explicitly looking for the directory name $Directory, not the value that should be substituted.
Also, your use of the wildcard "*" is highly likely to be broken in nearly all cases. If you quote it too much the shell won't expand it and find will look for asterisk as the link target. If you quote it too little it gets expanded too soon, and find will look for the first file name in the current directory as the link target, but then find some illegal stray arguments.
Code:
Directory="*/SomeTarget/*"
for i in `find . -lname "$Directory"`;do
echo found link $i
done
should work better. 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.
Try temporarily turning off bash filename expansion.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.