View Single Post

   
  #8 (permalink)  
Old 02-15-2008, 11:47 AM
Scott McMillan
 
Posts: n/a
Default Re: Losing variables after IFS Reply-To: scomsc@xenitec.on.ca

On Thu, 22 Jan 2004 20:18:31 GMT, Tom Parsons <cis@tegan.com> wrote:

>Scott McMillan enscribed:
>| On 22 Jan 2004 19:47:44 GMT, "Chris F.A. Johnson"
>| <c.fa.johnson@rogers.com> wrote:
>|
>| >On Thu, 22 Jan 2004 at 18:52 GMT, Scott McMillan wrote:
>| >> Hello all,
>|
>| <snipped>
>| >>
>| >> # more test
>| >> #!/bin/sh
>| >> cd /tmp
>| >> COPY="copy -omv"
>| >> $COPY /mnt/tst1.txt sdm1
>| >> IFS=``
>| >> $COPY /mnt/tst1.txt sdm2
>| >>
>| <snipped>
>| >>
>| >> # /mnt/test
>| >> copy file /mnt/tst1.txt
>| >> /mnt/test: copy -omv: not found
>| >
>| > Because there is no delimiter in IFS, there is nothing to split
>| > $COPY into a command and its arguments. The entire value of the
>| > variable is parsed as the command.
>| >
>| >> # ls -l /tmp
>| >> total 2
>| >> -rw-rw-rw- 1 root sys 29 Jan 22 08:20 sdm1
>| >>
>| < snipped own ignorance :-) >
>|
>| Ah, yes, I think I see it now. At the point that I set IFS=``, the
>| rest of the script is using NUL to separate ALL of the fields. I had
>| not considered that as I wrote the post.
>|
>| Thank you for pointing this out to me, Chris. Next question:
>| To maintain my variables through the rest of my script, could I do
>| something like
>| ORGIFS=$IFS
>| IFS=``
>| ... do some stuff
>| IFS=$ORGIFS
>|
>| or do I risk the same problem? AFAIK, IFS is initially set to space.
>| I suppose it would be just as easy to do IFS=` ` (set to space).
>
>Do this:
>oldIFS=$IFS
>IFS=$oldIFS
>
>If you reset it to a space, you may be in for a surprise. The default
>IFS are space, tab and newline.
>
>tom


Hi Tom,

Thanks for that, I'll give it a go and see what comes out.


Scott McMillan
Reply With Quote