LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-06-2010, 05:32 PM   #1
ProgrammerTim
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Rep: Reputation: 0
Spaces in command line switches


I am trying to encode files via mencoder. The file name has spaces in it. "test file.mkv". When I manually type the command in the terminal, everything works. But when I use a bash script (I'm reading it from a file) it doesn't. It gives me
Code:
File not found: '"test'
Below is the bash script I wrote
Code:
#!/bin/bash
# For testing, we have already built a file list, so just use that.
# ls *.mkv>files.lst
exec 10<files.lst
let count=0	
while read -u 10 FILE; do
	LINE="mencoder -of lavf -lavfopts format=mp4 -vf scale=1024:-3 -ovc x264 -x264encopts crf=28:vbv_maxrate=1500:nocabac:global_header:bframes=0 -oac faac -faacopts br=160:mpeg=4:object=2:raw -channels 2 -srate 48000 \"$FILE\" -o test.mp4"
	echo $LINE
	exec $LINE
done

exec 10>&-
files.lst contains only a single line (no newline) with
Code:
test file.mkv
On a related note, when I was first trying this simply on the command line, I had a file that had a double exclamation point. I found out that that is a shortcut of some kind for the previous command. My kludge to get around this was to try to execute a single exclamation point as a command, then to change the double exclamation point to a quadruple exclamation point. Is there a proper way (escape sequence or something) to pass double exclamation points to a command?
 
Old 10-06-2010, 05:50 PM   #2
criggie
LQ Newbie
 
Registered: Apr 2004
Posts: 1

Rep: Reputation: 0
Command line has weirdness that shell scripts avoid, and vice versa.

Make a habit of quoting variables.

Code:
exec 10<files.lst
let count=0	
while read -u 10 FILE; do
	echo "$FILE"
	mencoder -of lavf -lavfopts format=mp4 -vf scale=1024:-3 -ovc x264 -x264encopts crf=28:vbv_maxrate=1500:nocabac:global_header:bframes=0 -oac faac -faacopts br=160:mpeg=4:object=2:raw -channels 2 -srate 48000 "$FILE" -o test.mp4
done
exec 10>&-
Characters like non-ascii, Bang !, Ampersand &, Dash -, Newline \n, Backslash \ and so on can all cause problems - avoid them in filenames if possible, and always test for them to produce a robust script.

G'luck!
 
Old 10-06-2010, 05:54 PM   #3
ProgrammerTim
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks. For some reason, it never occurred to me to NOT use exec.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Moving file which it's name contain spaces by command line??? Mr.mick-duck Linux - General 6 03-14-2009 06:30 AM
[SOLVED] Remove extra spaces in a line vikas027 Programming 11 10-11-2008 09:20 AM
remove all spaces from a line in C xeon123 Programming 12 10-23-2007 02:29 AM
Use spaces in command line? Geminias Linux - Newbie 2 01-03-2006 08:37 PM
Spaces on command line odd Linux - Software 2 05-22-2004 09:17 AM


All times are GMT -5. The time now is 04:30 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration