This is a discussion on Losing variables after IFS within the Sco Unix forums, part of the Unix Operating Systems category; --> Hello all, I hope someone can point me in the right direction. I have the following script burned to ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello all, I hope someone can point me in the right direction. I have the following script burned to CD-ROM using mkisofs v1.14 and cdrecord 1.10 - both precompiled SCO Openserver binaries running on OSR5.0.6: # more test #!/bin/sh cd /tmp COPY="copy -omv" $COPY /mnt/tst1.txt sdm1 IFS=`` $COPY /mnt/tst1.txt sdm2 I mount the CD on my SCO system, and run the 'test' script: # ls -l /tmp total 0 # mount /dev/cd0 /mnt # ls -l /mnt total 4 -rwxr-xr-x 1 root sys 92 Jan 22 08:21 test -rw-rw-rw- 1 root sys 29 Jan 22 08:20 tst1.txt # /mnt/test copy file /mnt/tst1.txt /mnt/test: copy -omv: not found # ls -l /tmp total 2 -rw-rw-rw- 1 root sys 29 Jan 22 08:20 sdm1 As you can see, the first copy works fine, but my IFS= definition seems to 'break' my $COPY variable definition. This ONLY occurs when running the script on CD - Other installations that extract from tape/floppy (using tar) to the HD perform everything as expected. Can someone explain to me what the IFS=`` does to my $COPY? I'm not sure if it's due to the shell (Bourne), something to do with the mkisofs/cdrecord I'm using, etc. Thanks for any insight. (BTW, mkisofs command: /usr/local/bin/mkisofs -v -l -L -d -D -R -o image.iso $files) Scott McMillan |
| |||
| On Thu, 22 Jan 2004 19:21:25 GMT, Fabio Giannotti <fabiog@venmar.com> wrote: > > >> -----Original Message----- >> From: listmaster@xenitec.on.ca >> [mailto:listmaster@xenitec.on.ca] On Behalf Of Scott McMillan >> Sent: Thursday, January 22, 2004 12:53 PM >> To: distribution@xenitec.on.ca >> Subject: Losing variables after IFS >> >> >> Hello all, >> >> I hope someone can point me in the right direction. I have >> the following script burned to CD-ROM using mkisofs v1.14 and >> cdrecord 1.10 - both precompiled SCO Openserver binaries >> running on OSR5.0.6: >> >> # more test >> #!/bin/sh >> cd /tmp >> COPY="copy -omv" >> $COPY /mnt/tst1.txt sdm1 >> IFS=`` >> $COPY /mnt/tst1.txt sdm2 >> >> I mount the CD on my SCO system, and run the 'test' script: >> # ls -l /tmp >> total 0 >> # mount /dev/cd0 /mnt >> # ls -l /mnt >> total 4 >> -rwxr-xr-x 1 root sys 92 Jan 22 08:21 test >> -rw-rw-rw- 1 root sys 29 Jan 22 08:20 tst1.txt >> >> # /mnt/test >> copy file /mnt/tst1.txt >> /mnt/test: copy -omv: not found >> >> # ls -l /tmp >> total 2 >> -rw-rw-rw- 1 root sys 29 Jan 22 08:20 sdm1 >> >> As you can see, the first copy works fine, but my IFS= >> definition seems to 'break' my $COPY variable definition. >> This ONLY occurs when running the script on CD - Other >> installations that extract from tape/floppy (using tar) to >> the HD perform everything as expected. >> >> Can someone explain to me what the IFS=`` does to my $COPY? >> I'm not sure if it's due to the shell (Bourne), something to >> do with the mkisofs/cdrecord I'm using, etc. >> >Scott, > >That's really odd. I just tried it on my system and it has the exact same >effect, even though I'm not doing anything with a CD. That is, I just >created a little script and ran it from root and "broke" exactly the same >way. > >That is, setting it to null with either double quotes, single quotes or back >quotes causes the same behavior. Basically, after setting IFS to null the >system sees the entire variable "copy -vom" as one string, not two seperate >strings seperated by a space. > >So, you can't set IFS to null and have it work. > >You can see what setting IFS is doing by looking at the following: >IFS=";" >COPY="copy;-vom" >$copy file1 file2 > >Good luck, >Fabio Hi Fabio, Well, after reading your reply, I went back to my install scripts (the above is just to recreate the problem) and found that you are right, it's NOT just on CDs. My real scripts are finished with all variables BEFORE the IFS= line, so the issue never showed itself. Sorry for that bit of mis-information. But I'm not really sure I understand your example above. Is IFS _inserting_ it's value into my COPY variable, in place of a space? If so, I've been misinterpreting its use for awhile now, and better get back to RTFM! Thanks for your help. Scott McMillan |
| |||
| On Thu, 22 Jan 2004 at 18:52 GMT, Scott McMillan wrote: > Hello all, > > I hope someone can point me in the right direction. I have the > following script burned to CD-ROM using mkisofs v1.14 and cdrecord > 1.10 - both precompiled SCO Openserver binaries running on OSR5.0.6: > > # more test > #!/bin/sh > cd /tmp > COPY="copy -omv" > $COPY /mnt/tst1.txt sdm1 > IFS=`` > $COPY /mnt/tst1.txt sdm2 > > I mount the CD on my SCO system, and run the 'test' script: > # ls -l /tmp > total 0 > # mount /dev/cd0 /mnt > # ls -l /mnt > total 4 > -rwxr-xr-x 1 root sys 92 Jan 22 08:21 test > -rw-rw-rw- 1 root sys 29 Jan 22 08:20 tst1.txt > > # /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 > > As you can see, the first copy works fine, but my IFS= definition > seems to 'break' my $COPY variable definition. This ONLY occurs when > running the script on CD - Other installations that extract from > tape/floppy (using tar) to the HD perform everything as expected. > > Can someone explain to me what the IFS=`` does to my $COPY? I'm not > sure if it's due to the shell (Bourne), something to do with the > mkisofs/cdrecord I'm using, etc. -- Chris F.A. Johnson http://cfaj.freeshell.org ================================================== ================= My code (if any) in this post is copyright 2004, Chris F.A. Johnson and may be copied under the terms of the GNU General Public License |
| |||
| 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). Scott McMillan |
| |||
| Scott McMillan wrote: > Hello all, > > I hope someone can point me in the right direction. I have the > following script burned to CD-ROM using mkisofs v1.14 and cdrecord > 1.10 - both precompiled SCO Openserver binaries running on OSR5.0.6: > > # more test > #!/bin/sh > cd /tmp > COPY="copy -omv" > $COPY /mnt/tst1.txt sdm1 > IFS=`` > $COPY /mnt/tst1.txt sdm2 > > I mount the CD on my SCO system, and run the 'test' script: > # ls -l /tmp > total 0 > # mount /dev/cd0 /mnt > # ls -l /mnt > total 4 > -rwxr-xr-x 1 root sys 92 Jan 22 08:21 test > -rw-rw-rw- 1 root sys 29 Jan 22 08:20 tst1.txt > > # /mnt/test > copy file /mnt/tst1.txt > /mnt/test: copy -omv: not found > > # ls -l /tmp > total 2 > -rw-rw-rw- 1 root sys 29 Jan 22 08:20 sdm1 > > As you can see, the first copy works fine, but my IFS= definition > seems to 'break' my $COPY variable definition. This ONLY occurs when > running the script on CD - Other installations that extract from > tape/floppy (using tar) to the HD perform everything as expected. > > Can someone explain to me what the IFS=`` does to my $COPY? I'm not > sure if it's due to the shell (Bourne), something to do with the > mkisofs/cdrecord I'm using, etc. It prevents the expansion of $COPY from being seen as multiple words (the copy command and the -omv option string). 1. Instead of setting IFS to the output of a null command (with backticks), you should set it to the emtpy string (with single quotes). 2. You could use 2 separate variables (e.g. copy_program and copy_options) instead of just 1 (COPY, which isn't exported and as a matter of convention shouldn't be uppercase). 3. But setting IFS doesn't serve any purpose here, so why bother at all? -- Kevin Rodgers |
| |||
| On Thu, 22 Jan 2004 at 20:03 GMT, Scott McMillan wrote: > 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). Why change it at all? It is set to space, tab and newline by default. -- Chris F.A. Johnson http://cfaj.freeshell.org ================================================== ================= My code (if any) in this post is copyright 2004, Chris F.A. Johnson and may be copied under the terms of the GNU General Public License |
| |||
| 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 -- ================================================== ======================== Tom Parsons tom@tegan.com ================================================== ======================== |
| |||
| 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 |
| |||
| In article <5r50109oeus8re6110cg08ljhi87kslvik@4ax.com>, Scott McMillan <smcm@usa.net> wrote: > IFS=`` It's not related to your original problem, but you have the wrong type of quotes there. Those are backticks, and they're used for command substitution. You should be using single quotes: IFS='' -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** |
| ||||
| On Fri, 23 Jan 2004 at 20:11 GMT, Barry Margolin wrote: > In article <5r50109oeus8re6110cg08ljhi87kslvik@4ax.com>, > Scott McMillan <smcm@usa.net> wrote: > >> IFS=`` > > It's not related to your original problem, but you have the wrong type > of quotes there. Those are backticks, and they're used for command > substitution. You should be using single quotes: > > IFS='' Effectively, they are the same in this instance. The command substitution will take longer in most, if not all, shells. -- Chris F.A. Johnson http://cfaj.freeshell.org ================================================== ================= My code (if any) in this post is copyright 2004, Chris F.A. Johnson and may be copied under the terms of the GNU General Public License |