LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2008, 11:44 PM   #1
Ransak
Member
 
Registered: Nov 2005
Posts: 35

Rep: Reputation: 15
Escaping spaces in a variable


Hi,

I've been working on a way to automatically convert some of my TiVo files with a shell script. I'm using tivodecode to accomplish the actual conversion from a .TiVo file to a .mpg file.

My problem is when a TiVo file arrives, it's full of spaces. For example:

Code:
-rw-r--r-- 1 root root 388959059 Feb  2 18:03 Ask This Old House - Window pane; safety glass (Recorded Sun Mar 18 2007 06 30AM AETV).TiVo
I've written a simple script to convert this using tivodecode:

Code:
#!/bin/bash
cd /data/videos
for a in $(ls -1 *.TiVo) ; do tivodecode -o $a.mpg $a ; done
The problem appears to be the spaces in the file names. When they're read into the a variable, they aren't escaped correctly, so tivodecode fails.

How can I escape these properly in my shell script? Escaped properly, tivodecode works well. I'd like to keep the spaces (as heinous as they are) in the file name since this is what certain applications I'm using like.
 
Old 02-09-2008, 11:53 PM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Use double quotes: for a in $(ls -1 *.TiVo) ; do tivodecode -o "$a".mpg "$a" ; done
 
Old 02-10-2008, 12:05 AM   #3
Ransak
Member
 
Registered: Nov 2005
Posts: 35

Original Poster
Rep: Reputation: 15
Thanks for the reply Nylex.

It doesn't work correctly, however.

Code:
linux:/data/videos # ./tconvert.sh
Ask: No such file or directory
This: No such file or directory
Old: No such file or directory
House: No such file or directory
Encryption by QUALCOMM ;)
It begins to convert the first video but the output is filename -.mpg . All files are written to this (and thus overwriting) the previous converted file. I won't go into how annoying it is to have a filename start with a dash

Last edited by Ransak; 02-10-2008 at 12:11 AM.
 
Old 02-10-2008, 01:54 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by Nylex View Post
Use double quotes: for a in $(ls -1 *.TiVo) ; do tivodecode -o "$a".mpg "$a" ; done
no need to use ls
Code:
for a in *.Tivo
do
    blah blah "$a" 
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
tcsh escaping ' or $ smk123 Programming 3 10-29-2005 03:35 PM
javascript escaping / rblampain Programming 1 09-19-2005 07:16 AM
Huge spaces in all variable width fonts Dare Linux - Software 0 10-21-2004 12:45 PM
Escaping from .bash_history ivanatora Linux - General 2 04-25-2004 04:37 PM
need to innitialize string variable with multiple spaces clsonnt Programming 3 08-11-2003 10:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:12 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