Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page [newbieness] recursive directory listing as a variable?
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Reply
 
Thread Tools Display Modes
Old 07-02-2007   #1 (permalink)
the dsc
Linux Newbie
 
Join Date: Apr 2007
Posts: 133
[newbieness] recursive directory listing as a variable? [solved]

I'm using the following lines as part of a script to get me a random wallpaper slideshow:

Code:
LOCATION=~/.kde/share/wallpapers
Background=$(ls ${LOCATION})
background=($Background)                
num_background=${#background[*]}       
Esetroot -fit ${LOCATION}/${background[$((RANDOM%num_background))]}
I've copied it from somewhere, maybe from here.

It works fine, but I'd like to organize my wallpapers in many folders, both to be organized and also to solve a little bit the problem of a list with too many files when manually setting the wallpaper on fluxbox menu, as I would have the list split into smaller sublists.

So, is there some way to make this "location" variable to be recursive?

A sort of workaround I've thought would be to have organized real files in folders and another folder with symbolic links (or something like that) to each file, or perhaps some sort of "meta folder" whose content would be automatically the content of a certain list of folders or something like that, not requiring a link to each file individually. I suppose both of these things can be done, but I don't know how to do any.

edit: I've figured how to make links to individual files, but I think that's the worst solution possible and I don't really learn anything valuable...

Last edited by the dsc; 07-02-2007 at 05:19 PM. Reason: solved
the dsc is offline   Reply With Quote
Old 07-02-2007   #2 (permalink)
sdousley
Linux Guru
 
sdousley's Avatar
 
Join Date: Feb 2004
Posts: 1,766
Best way to make it recursive would probably be to use the "find" command instead of the "ls" command eg: change:

Code:
Background=${ls ${LOCATION}}
to:
Code:
Background=${find ${location} -type f -iname '*'}
You can change the -iname variable to only include jpg's or only png's etc eg: "-iname '*jpg'"

HTH
__________________
"I am not an alcoholic, alcoholics go to meetings"
Registered Linux user = #372327
sdousley is offline   Reply With Quote
Old 07-02-2007   #3 (permalink)
the dsc
Linux Newbie
 
Join Date: Apr 2007
Posts: 133
Thanks! The scheme you presented didn't work, but made me realize that there is this "ls" that is just the same thing as the command line "ls" ( ), so I used "ls -R" which stands for recursive, and it did work


Is there any command line I could use to just retrieve which value a given variable has at a time?

More or less like, if I were in basic (language), typing "print $Background" and pressing enter...
the dsc is offline   Reply With Quote
Old 07-02-2007   #4 (permalink)
devils casper
Ghost
 
devils casper's Avatar
 
Join Date: Jun 2006
Location: Chandigarh, INDIA
Posts: 18,101
Code:
echo $Background
check this too. LinuxCommand.org: Learn the Linux command line. Write shell scripts.
__________________
New Users: Read This First
If you woke up breathing, Congratulations! You get another chance.

devils casper is offline   Reply With Quote
Old 07-02-2007   #5 (permalink)
the dsc
Linux Newbie
 
Join Date: Apr 2007
Posts: 133
Thanks guys.

But just in case sdousley went a bit surprised with my simpler "solution", is because it doesn't really work as I thought.

I've made a few file shortcuts and forgot to delete them, so I thought I was getting files from sudirectories, when, instead, I'm getting only filenames but not the full path, which seems to be impossible only with "ls", and is needed to the whole thing work. I've searching a little bit and the way to emulate that seems to be using "find".
the dsc is offline   Reply With Quote
Old 07-02-2007   #6 (permalink)
the dsc
Linux Newbie
 
Join Date: Apr 2007
Posts: 133
SOLVED!

The problem was that I should have used parenthesis "externaly" and curly brackets within, I think. Or at least I did that with sdousley's suggested solution and now it definately works.

Before it was giving an error message, "bad substitution", and eventually I noticed that difference with brackets and parenthesis, not that even crossed my mind that it may have anything to do with "bad substitution", but seemed logical and harmless, then I tried.



A final note:

another modification needed is removing the "location" part after the esetroot command, or else you'll get a redundance, part of the file address will appear twice in the variable. In my case, instead of getting something like:

/.kde/share/wallpapers/landscapes/1.jpg

I'd get:

/.kde/share/wallpapers//.kde/share/wallpapers/landscapes/1.jpg

Or something like that.

The odd thing is that when I first edited to fix only the bracket issue, it worked anyway, despite of that, somehow... but after I restarted fluxbox, no wallpaper appeared, and I tested the script through a terminal, where the problem became evident.

Summarizing, the last line should be:

Esetroot -fit ${background[$((RANDOM%num_background))]}


the dsc is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installation problem satimis Misc 2 09-30-2005 02:52 AM
help installing superkaramba ultrA_Cowboy Installation 13 02-26-2005 09:22 PM
Problems with SSH ParalyZer Mandriva Linux Help 4 09-27-2004 01:41 PM
SDL headers problem daemox Linux Applications 0 07-27-2004 06:44 AM
libstdc++.so.4 jimlaflin Installation 18 06-15-2003 08:40 AM




All times are GMT. The time now is 06:52 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0