LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 08-25-2012, 12:50 AM   #1
sumeet inani
Member
 
Registered: Oct 2008
Posts: 881
Blog Entries: 26

Rep: Reputation: 47
pass a file name with space as single argument to script


find . -type f -exec my-script '{}' ';'
where my-script has
Code:
ffmpeg -i $1 2> ~/file-codec-analysis.txt
The problem is when file name has 'space separated words' then $1 becomes only the first word.
What should I do so that $1 becomes 'file with many words'?
 
Old 08-25-2012, 03:01 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,517
Blog Entries: 2

Rep: Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018
Just quote the $1, like this:
Code:
ffmpeg -i "$1" 2> ~/file-codec-analysis.txt
 
1 members found this post helpful.
Old 08-25-2012, 10:03 AM   #3
sumeet inani
Member
 
Registered: Oct 2008
Posts: 881
Blog Entries: 26

Original Poster
Rep: Reputation: 47
will try.
 
Old 08-25-2012, 01:44 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
As you've discovered, it's vitally important in scripting to understand how it processes arguments and whitespace. Read through these three links for a full description:

http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes

The secret is generally to always quote your variables and other parameters. Never leave them off unless you know exactly what you're doing, and have some over-riding need for it.
 
Old 08-26-2012, 12:25 AM   #5
sumeet inani
Member
 
Registered: Oct 2008
Posts: 881
Blog Entries: 26

Original Poster
Rep: Reputation: 47
Thank you TobiSGD .
That worked fine .

BTW , I will surely read as suggested by David the H..

I wonder - Have you guys done some certification course in linux OR is it that 'with experience comes knowledge' .
Also I would like to know how members become moderator , guru , senior member on this forum ? There must be some pre-requisites .
 
Old 08-26-2012, 04:45 AM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,517
Blog Entries: 2

Rep: Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018Reputation: 4018
Knowledge comes with experience and with reading, reading, reading.

To will automatically get the Senior Member label when you have 1000 posts and the Guru label (which can be changed to some other labels, like LQ Veteran) when you have 5000 posts.
To become a moderator here you have to attend a secret initiation ceremony after fulfilling the prerequisites, which are also secret.
 
  


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
How do I pass complicated commands (With bar's) as an argument to another script? theaceoffire Programming 8 04-22-2010 09:40 AM
[SOLVED] Pass space (or string escaped) as argument to shell script. scmbg Programming 1 10-07-2009 10:15 AM
[SOLVED] pass file-name as command line argument vikas027 Programming 2 10-14-2008 11:52 PM
Howto pass an argument to alias of a script? Goose1 Programming 1 02-17-2008 06:14 PM
PHP pass argument to shell script monzter Programming 2 08-14-2004 06:16 AM


All times are GMT -5. The time now is 01:21 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration