Preserving Blanks in Parameters to Shell Script
Hi. I want to write a script which will nice ffmpeg whatever parameters it is given - ie: #!/bin/sh nice ffmpeg $* # However, what if I have a file named `file one' I would like to type `myscript -i file\ one output.whatever` I do not want to change what I type - the script needs to be a drop-in replacement for the ffmpeg command. Is there any way to do make the script preserve the backslashed space ? TIA -- The day is short, and the work is great,| Aharon Schkolnik and the laborers are lazy, and the reward | is great, and the Master of the house is| aschkol...@gmail.com impatient. - Ethics Of The Fathers Ch. 2| 054 3344135 ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Preserving Blanks in Parameters to Shell Script
use $@ instead of $* On Mon, Jun 14, 2010 at 3:27 PM, Aharon Schkolnik aschkol...@gmail.comwrote: Hi. I want to write a script which will nice ffmpeg whatever parameters it is given - ie: #!/bin/sh nice ffmpeg $* # However, what if I have a file named `file one' I would like to type `myscript -i file\ one output.whatever` I do not want to change what I type - the script needs to be a drop-in replacement for the ffmpeg command. Is there any way to do make the script preserve the backslashed space ? TIA -- The day is short, and the work is great,| Aharon Schkolnik and the laborers are lazy, and the reward | is great, and the Master of the house is| aschkol...@gmail.com impatient. - Ethics Of The Fathers Ch. 2| 054 3344135 ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Preserving Blanks in Parameters to Shell Script
On Monday, June 14, 2010, Noam Meltzer wrote: use $@ instead of $* Does that work for you ? I still get the same results - the script treates file\ one as two parameters - file and one. On Mon, Jun 14, 2010 at 3:27 PM, Aharon Schkolnik aschkol...@gmail.comwrote: Hi. I want to write a script which will nice ffmpeg whatever parameters it is given - ie: #!/bin/sh nice ffmpeg $* # However, what if I have a file named `file one' I would like to type `myscript -i file\ one output.whatever` I do not want to change what I type - the script needs to be a drop-in replacement for the ffmpeg command. Is there any way to do make the script preserve the backslashed space ? TIA -- The day is short, and the work is great,| Aharon Schkolnik and the laborers are lazy, and the reward | is great, and the Master of the house is| aschkol...@gmail.com impatient. - Ethics Of The Fathers Ch. 2| 054 3344135 ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Preserving Blanks in Parameters to Shell Script
On 14 June 2010 22:48, Aharon Schkolnik aschkol...@gmail.com wrote: On Monday, June 14, 2010, Noam Meltzer wrote: use $@ instead of $* Does that work for you ? I still get the same results - the script treates file\ one as two parameters - file and one. 1. Try switching to #!/bin/bash - I think the $@ is a bash-specific extension which might be disabled if bash is called as sh. 2. Add double-quotes around the $@, (ie. make it read 'nice ffmpege $@' without the single-quotes) BTW - if the nice ffmpeg is the last line in the script then you can add an exec in front of it. --Amos ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Preserving Blanks in Parameters to Shell Script
I'm sorry. I tend to forget why I hate shell scripts. Use $@ instead. (checked it this time, it works ;-) ) 2010/6/14 Aharon Schkolnik aschkol...@gmail.com On Monday, June 14, 2010, Noam Meltzer wrote: use $@ instead of $* Does that work for you ? I still get the same results - the script treates file\ one as two parameters - file and one. On Mon, Jun 14, 2010 at 3:27 PM, Aharon Schkolnik aschkol...@gmail.comwrote: Hi. I want to write a script which will nice ffmpeg whatever parameters it is given - ie: #!/bin/sh nice ffmpeg $* # However, what if I have a file named `file one' I would like to type `myscript -i file\ one output.whatever` I do not want to change what I type - the script needs to be a drop-in replacement for the ffmpeg command. Is there any way to do make the script preserve the backslashed space ? TIA -- The day is short, and the work is great,| Aharon Schkolnik and the laborers are lazy, and the reward | is great, and the Master of the house is| aschkol...@gmail.com impatient. - Ethics Of The Fathers Ch. 2| 054 3344135 ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Preserving Blanks in Parameters to Shell Script
On Monday, June 14, 2010, Noam Meltzer wrote: I'm sorry. I tend to forget why I hate shell scripts. Use $@ instead. (checked it this time, it works ;-) ) Yep - looks like nice ffmpeg $@ does the trick. Thanks ! 2010/6/14 Aharon Schkolnik aschkol...@gmail.com On Monday, June 14, 2010, Noam Meltzer wrote: use $@ instead of $* Does that work for you ? I still get the same results - the script treates file\ one as two parameters - file and one. On Mon, Jun 14, 2010 at 3:27 PM, Aharon Schkolnik aschkol...@gmail.comwrote: Hi. I want to write a script which will nice ffmpeg whatever parameters it is given - ie: #!/bin/sh nice ffmpeg $* # However, what if I have a file named `file one' I would like to type `myscript -i file\ one output.whatever` I do not want to change what I type - the script needs to be a drop-in replacement for the ffmpeg command. Is there any way to do make the script preserve the backslashed space ? TIA -- The day is short, and the work is great,| Aharon Schkolnik and the laborers are lazy, and the reward | is great, and the Master of the house is| aschkol...@gmail.com impatient. - Ethics Of The Fathers Ch. 2| 054 3344135 ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Preserving Blanks in Parameters to Shell Script
Quoting Noam Meltzer tsn...@gmail.com: use $@ instead of $* But put it in quotes: $@. Otherwise the effect is lost. Herouth ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Preserving Blanks in Parameters to Shell Script
On Monday 14 Jun 2010 15:27:43 Aharon Schkolnik wrote: Hi. I want to write a script which will nice ffmpeg whatever parameters it is given - ie: #!/bin/sh nice ffmpeg $* # However, what if I have a file named `file one' I would like to type `myscript -i file\ one output.whatever` I do not want to change what I type - the script needs to be a drop-in replacement for the ffmpeg command. Is there any way to do make the script preserve the backslashed space ? Yes, use quotes: [shell] # Untested #!/bin/sh nice ffmpeg $@ [/shell] $@ when in quotes causes it to be something like $1 $2 $3 $4 , and so forth up to the number of quotes. The whitespace-in-shell-variables-handling is part of a general code/markup injection problem: * http://community.livejournal.com/shlomif_tech/35301.html * http://community.livejournal.com/shlomif_tech/14671.html Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ My Aphorisms - http://www.shlomifish.org/humour.html God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Preserving Blanks in Parameters to Shell Script
On Mon, Jun 14, 2010 at 11:02:11PM +1000, Amos Shapira wrote: On 14 June 2010 22:48, Aharon Schkolnik aschkol...@gmail.com wrote: On Monday, June 14, 2010, Noam Meltzer wrote: use $@ instead of $* Does that work for you ? I still get the same results - the script treates file\ one as two parameters - file and one. 1. Try switching to #!/bin/bash - I think the $@ is a bash-specific extension which might be disabled if bash is called as sh. It's not bash specific. Mind you, on some systems /bin/sh may point to something other than bash. -- Tzafrir Cohen | tzaf...@jabber.org | VIM is http://tzafrir.org.il || a Mutt's tzaf...@cohens.org.il || best tzaf...@debian.org|| friend ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il