LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   pass a file name with space as single argument to script (https://www.linuxquestions.org/questions/linux-newbie-8/pass-a-file-name-with-space-as-single-argument-to-script-4175423900/)

sumeet inani 08-25-2012 01:50 AM

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'?

TobiSGD 08-25-2012 04:01 AM

Just quote the $1, like this:
Code:

ffmpeg -i "$1" 2> ~/file-codec-analysis.txt

sumeet inani 08-25-2012 11:03 AM

will try.

David the H. 08-25-2012 02:44 PM

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.

sumeet inani 08-26-2012 01:25 AM

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 .

TobiSGD 08-26-2012 05:45 AM

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.


All times are GMT -5. The time now is 04:17 PM.