Could use some help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Could use some help
# 1  
Old 11-25-2007
Could use some help

Hello All,

I could use some help, I am trying to write a small script for my mythTV dvr but I am in over my head (I am new to bash scripting),

I am trying to run "ls -tr *.avi | tail -10" to get a list of the last 10 avi's I have added, and then to a ln -s of the list to create a symlink of each file to a directory.

The issue is if I do theItems=`ls -tr *.avi | tail -10` They are a single string, so I tried "set -- $theItems" but spaces in file names become a value.

Can anyone give a direction/assistance to how I might be able to do this?

Thanks
Bryan
# 2  
Old 11-25-2007
It would help if you could give the listing of your current script. It sounds like you are using 'for ...'. I suggest using a while loop instead. Something like this:

Code:
ls -tr *.avi | tail -10 | while read line; do
### do your linking and stuff here. the variable $line holds the filename
### you can enclose in " " if you want to be absolutely sure
### about spaces not being mis-interpreted
done

# 3  
Old 11-25-2007
Never Mind, I found xargs to be easier

ls -tr *.avi | tail -10 | xargs -I{} ln -s /Video_Media/{} /Video_Media/Newest/
In case anyone cares Smilie

Thanks for assisting.

Bryan
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question