The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-25-2007
bcromwell bcromwell is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 2
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 (permalink)  
Old 11-25-2007
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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 (permalink)  
Old 11-25-2007
bcromwell bcromwell is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 2
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

Thanks for assisting.

Bryan
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0