[olug] sed and sh
Adam Haeder
adamh at omaha.org
Tue Feb 4 22:32:57 UTC 2003
Looks like you're running into a problem that plagues me often. I put
together a nice sed regular expression match that works fine. Then I
incorporate it into a script, and it doesn't work.
When you put a sed script inside the backticks (`), you have to
DOUBLE-ESCAPE everything. So if your original sed script was
sed s/\\//i/g (which replaces all instances of / with i
inside ticks it needs to be
sed s/\\\//i/g
Try it from a shell:
[adamh at adam adamh]$ cat test
this/this
[adamh at adam adamh]$ cat test | sed s/\\//i/g
thisithis
[adamh at adam adamh]$ me=`cat test | sed s/\\//i/g`
sed: -e expression #1, char 6: Unknown option to 's'
[adamh at adam adamh]$ me=`cat test | sed s/\\\//i/g`
[adamh at adam adamh]$ echo $me
thisithis
[adamh at adam adamh]$
Strange but true.
--
Adam Haeder
Technical Coordinator, AIM Institute
adamh at omaha.org
(402) 345-5025 x115
PGP Public key: http://www.omaha.org/~adamh/pgp.html
On Tue, 4 Feb 2003, Jon H. Larsen wrote:
>
>
> I'm currently modifying a script that came with Hylafax where I am
> attaching a PDF version of the Tif fax document to an email, and
> delivering it.
>
> I created a TEST script to work on the bit of code that I need to truncate
> the filename.
>
> #!/bin/sh
> #
> # trunctest.sh
>
>
> FILE="$1"
> TRUNCFILE=`echo $FILE | /bin/sed -e 's/recvq\///' | /bin/sed -e 's/\.tif//'`
>
> echo $TRUNCFILE
>
>
> Run it like so:
> ./trunctest.sh recvq/fax00022.tif
>
> output:
> fax00022
>
> Works great.
>
> When I stick the lines in the production faxrcvd script, output is always
> blank.
>
> FILE="$1"
> TRUNCFILE=`echo $FILE | /bin/sed -e 's/recvq\///' | /bin/sed -e 's/\.tif//'`
>
> $TRUNCFILE is only used in echo statements in the script, and is only
> defined once.
>
> I've tried to use some of the PDF scripts provided by another source, but
> they didn't work as I had expected them. This truncate issue is the only
> thing holding me back from putting fax receive into production in our
> environment (send has been running for a year now). The script will
> deliver a PDF, but I'd rather have a more descriptive filename other than
> ".PDF" on the attachment. :)
>
> Puzzled...
> Jon L.
>
>
>
More information about the OLUG
mailing list