semi OT: sh scripting problem
(This is probably a FAQ, and I'll take a pointer (or even the magic words to identify the problem) instead of an answer.) Let's suppose I have a file FILE, with contents: foo bar grill baz If I do cat FILE, everything comes out fine. If, however, I write a script: #!/bin/sh for i in `cat FILE` do . . . . done $i is set to foo bar grill baz Is there a way within the script - or, failing that, by modifying FILE - to not break at the whitespace? Robert Huff ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: semi OT: sh scripting problem
On Wednesday 01 August 2007 09:35:44 Robert Huff wrote: (This is probably a FAQ, and I'll take a pointer (or even the magic words to identify the problem) instead of an answer.) Let's suppose I have a file FILE, with contents: foo bar grill baz If I do cat FILE, everything comes out fine. If, however, I write a script: #!/bin/sh for i in `cat FILE` do . . . . done $i is set to foo bar grill baz Is there a way within the script - or, failing that, by modifying FILE - to not break at the whitespace? I'm sure someone will give you a more elegant solution, but short of using sed or awk (my preference), this might help: $ cat test.sh #!/bin/sh myloop() { while read line; do echo $line done } cat test.sh | myloop hth... don Robert Huff ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] -- Don Hinton don.hinton at vanderbilt.edu or hintonda at gmail.com Institute for Software Integrated Systems (ISIS), Vanderbilt University tel: 615.480.5667 or 615.870.9728 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: semi OT: sh scripting problem
On Wed, 2007-08-01 at 10:35 -0400, Robert Huff wrote: (This is probably a FAQ, and I'll take a pointer (or even the magic words to identify the problem) instead of an answer.) Let's suppose I have a file FILE, with contents: foo bar grill baz If I do cat FILE, everything comes out fine. If, however, I write a script: #!/bin/sh for i in `cat FILE` cat FILE | while read i do . . . . done $i is set to foo bar grill baz Is there a way within the script - or, failing that, by modifying FILE - to not break at the whitespace? Robert Huff signature.asc Description: This is a digitally signed message part
Re: semi OT: sh scripting problem
Am Mittwoch 01 August 2007 16:35:44 schrieb Robert Huff: Is there a way within the script - or, failing that, by modifying FILE - to not break at the whitespace? If you're using bash, set IFS to the newline only before looping. I guess the tcsh also has a similar setting, but I wouldn't know where to look. --- IFS= for i in `cat file` do ... done --- HTH! -- Heiko Wundram Product Application Development ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: semi OT: sh scripting problem
On Aug 1, 2007, at 9:54 AMAug 1, 2007, Heiko Wundram (Beenic) wrote: Am Mittwoch 01 August 2007 16:35:44 schrieb Robert Huff: Is there a way within the script - or, failing that, by modifying FILE - to not break at the whitespace? If you're using bash, set IFS to the newline only before looping. I guess the tcsh also has a similar setting, but I wouldn't know where to look. --- IFS= for i in `cat file` do ... done This also works for sh. To the OP, simply add the lines above your for listed above to your script, and it should work. No bash required. Eric Crist ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: semi OT: sh scripting problem
Eric Crist writes: If you're using bash, set IFS to the newline only before looping. I guess the tcsh also has a similar setting, but I wouldn't know where to look. --- IFS= This also works for sh. To the OP, simply add the lines above your for listed above to your script, and it should work. No bash required. Tested and confirmed. Thanks everyone - the script works. Robert Huff ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]