LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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: 908
Blog Entries: 26

Rep: Reputation: 49
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: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
will try.
 
Old 08-25-2012, 01:44 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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: 908

Original Poster
Blog Entries: 26

Rep: Reputation: 49
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: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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