[Sugar-devel] Quoting in shell scripts (was: Re: [sugar-devel] Recent fiddlings with Print Support)
Andrés Ambrois
andresambrois at gmail.com
Thu May 14 02:14:03 EDT 2009
On Wednesday 13 May 2009 08:03:22 am Vamsi Krishna Davuluri wrote:
> Thanks. I have taken into account your suggestions and made another
script.
Thank you all for helping out! Here are a few other comments:
>
> #!/bin/bash -e
> # CUPS filter to process ODT files using abiword
>
>
> # $6 happens to be the path to file passed as argument
> fn="$6"
>
> #in case its not defined
> TMPDIR="/tmp"
See Jona's comments
> # we are creating a dummy folder, which can take different file types
using
> mkdir, change to ="/tmp/cups-odftops"
> sandbox="${TMPDIR-/tmp}/cups-odftops.$$$$"
> (umask 077 && mkdir "$sandbox") || exit 1
>
> #our two dummy files
> fn1="$sandbox/temp123.odt"
> cp "$fn" "$fn1"
Do you need to cp? Can't you symlink? Copying potentially large files is a
problem.
> # Call abiword quietly, securely
> abiword --to="ps" "$fn1"
> fn2="`echo "$fn1" | sed -e 's/odt/ps/' `"
fn2=`echo "$fn1" | sed 's/\.odt$/\.ps/'`
> #check if our version doesn't require an intermediate conversion, if it
> does, do it, else break;
>
> if [ -n "`grep -q "%!PS-Adobe-3.0" < "$fn2" `" ];then
grep -q is always silent, and [ -n ] tests for string length nonzero, so this
will always fail.
I guess you're trying to see if the conversion failed (does not contain
"%!PS-Adobe-3.0" ), so you should need:
if [ -z `grep "%!PS-Adobe-3.0" < "$fn2"` ]; then
> abiword --to="doc" "$fn1"
> abiword --to="ps" "`echo "$fn1" | sed -e 's/odt/doc/' `"
> fi
Again, watch out for that sed.
--
Andrés
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.sugarlabs.org/archive/sugar-devel/attachments/20090514/33b6513e/attachment.htm
More information about the Sugar-devel
mailing list