Unix administration - bourne-sh behavior

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > July 2004 > bourne-sh behavior





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author bourne-sh behavior
familie oehler

2004-07-04, 3:22 am

hi

i was programing installation procedures based on bourne-sh, sed, awk and all
other nice staff.

but than i run into troubles with the bourne-sh.

i found out the jsh (bourne-sh in solaris) is parsing strings in a rather
funny way. i contacted sun and the answer was - that's the way bourne sh is
working since ever. i hardly can believe this.

i tried my old 286 with interactive unix (1989) - but it does not work any
more. the ega monitor is missing. i so try to figure out the behavior of the
real bourne-sh by contacting other unix poeple.

the problem is simple: empty tokens are ignored. no other parsing algorythm in
any library or tool like awk, sed ... behave that way. anyone who has
experience in parsing information knows - it does not make sense because your
loosing orientation.

i created a verry simple script testing the problem and showing the testsuite.
if you are running any at&t or bsd ?nix like SunOS (not solaris), unixware, sgi
or even svr4 implementation on amdahl, please copy the following script and
send the output to oehlers@bluewin.ch. please make sure /bin/sh is a bourne-sh
(linux is bash and not bourne).
[vbcol=seagreen]
#!/bin/sh
LIST="a:b:c:::d:e:f"
IFS=':'
set $LIST
echo "======= part system information ================
uname -a
ps
file /bin/sh
echo "======= part system information ================
if [ $# -lt 8 ] ; then
echo "NOK==> found only $# token"
else
echo "OK==> found all 8 token"
fi
<<<< test.sh

thanks for help

george oehler


Barry Margolin

2004-07-04, 5:52 pm

In article <40e7a018$0$332$4d4ef98e@read.news.ch.uu.net>,
"familie oehler" <oehlers@bluewin.ch> wrote:

> hi
>
> i was programing installation procedures based on bourne-sh, sed, awk and all
> other nice staff.
>
> but than i run into troubles with the bourne-sh.
>
> i found out the jsh (bourne-sh in solaris) is parsing strings in a rather
> funny way. i contacted sun and the answer was - that's the way bourne sh is
> working since ever. i hardly can believe this.
>
> i tried my old 286 with interactive unix (1989) - but it does not work any
> more. the ega monitor is missing. i so try to figure out the behavior of the
> real bourne-sh by contacting other unix poeple.
>
> the problem is simple: empty tokens are ignored. no other parsing algorythm
> in
> any library or tool like awk, sed ... behave that way. anyone who has
> experience in parsing information knows - it does not make sense because your
> loosing orientation.


Remember, the word parsing algorithm is primarily intended for parsing
command lines, which use whitespace as the delimiter. If you typed:

cat foo bar

would you really expect it to operate differently from

cat foo bar

? Do you expect it to look for a file named "" because there's an
"empty token" between the two spaces?

If you want a tool that doesn't treat a sequence of delimiters as a
single delimiter, try "cut".

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Heiner Steven

2004-07-04, 5:52 pm

familie oehler wrote:

[...]
> the problem is simple: empty tokens are ignored. no other parsing algorythm in
> any library or tool like awk, sed ... behave that way. anyone who has
> experience in parsing information knows - it does not make sense because your
> loosing orientation.
>
> i created a verry simple script testing the problem and showing the testsuite.
> if you are running any at&t or bsd ?nix like SunOS (not solaris), unixware, sgi
> or even svr4 implementation on amdahl, please copy the following script and
> send the output to oehlers@bluewin.ch. please make sure /bin/sh is a bourne-sh
> (linux is bash and not bourne).
>
>
> #!/bin/sh
> LIST="a:b:c:::d:e:f"
> IFS=':'
> set $LIST
> echo "======= part system information ================
> uname -a
> ps
> file /bin/sh
> echo "======= part system information ================
> if [ $# -lt 8 ] ; then
> echo "NOK==> found only $# token"
> else
> echo "OK==> found all 8 token"
> fi
> <<<< test.sh


Your script parses LIST to 8 tokens with the following
shells (Linux):

ash ASH
bash BASH 2.05b.0(1)-release
pdksh KSH @(#)PD KSH v5.2.14 99/07/13.2
ksh93 KSH93 Version M 1993-12-28 m

"zsh" didn't parse the list at all, but set one single argument
("a:b:c:::d:e:f"):

zsh ZSH 4.1.1

Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
Michael Tosch

2004-07-05, 5:53 pm



familie oehler wrote:
> hi
>
> i was programing installation procedures based on bourne-sh, sed, awk and all
> other nice staff.
>
> but than i run into troubles with the bourne-sh.
>
> i found out the jsh (bourne-sh in solaris) is parsing strings in a rather
> funny way. i contacted sun and the answer was - that's the way bourne sh is
> working since ever. i hardly can believe this.
>
> i tried my old 286 with interactive unix (1989) - but it does not work any
> more. the ega monitor is missing. i so try to figure out the behavior of the
> real bourne-sh by contacting other unix poeple.
>
> the problem is simple: empty tokens are ignored. no other parsing algorythm in
> any library or tool like awk, sed ... behave that way. anyone who has
> experience in parsing information knows - it does not make sense because your
> loosing orientation.
>
> i created a verry simple script testing the problem and showing the testsuite.
> if you are running any at&t or bsd ?nix like SunOS (not solaris), unixware, sgi
> or even svr4 implementation on amdahl, please copy the following script and
> send the output to oehlers@bluewin.ch. please make sure /bin/sh is a bourne-sh
> (linux is bash and not bourne).
>
>
>
> #!/bin/sh
> LIST="a:b:c:::d:e:f"
> IFS=':'
> set $LIST
> echo "======= part system information ================
> uname -a
> ps
> file /bin/sh
> echo "======= part system information ================
> if [ $# -lt 8 ] ; then
> echo "NOK==> found only $# token"
> else
> echo "OK==> found all 8 token"
> fi
> <<<< test.sh
>
> thanks for help
>
> george oehler
>
>


Yes, bash and ksh do

bash-2.03$ LIST="a:b:c:::d:e:f"
bash-2.03$ IFS=':'
bash-2.03$ set $LIST
bash-2.03$ echo $#
8
bash-2.03$ LIST="a b c d e f"
bash-2.03$ IFS=' '
bash-2.03$ set $LIST
bash-2.03$ echo $#
6

i.e. treat white-space and non-white-space delimiters differently.
While Bourne shell does not differentiate.

Stephane CHAZELAS

2004-07-09, 11:56 am

2004-07-04, 18:38(+02), Heiner Steven:
[...]
[...][vbcol=seagreen]
> Your script parses LIST to 8 tokens with the following
> shells (Linux):
>
> ash ASH
> bash BASH 2.05b.0(1)-release
> pdksh KSH @(#)PD KSH v5.2.14 99/07/13.2
> ksh93 KSH93 Version M 1993-12-28 m
>
> "zsh" didn't parse the list at all, but set one single argument
> ("a:b:c:::d:e:f"):

[...]

Yes, that's a feature of zsh, while other shells could be
regarded bogus in that concern. In zsh, you have to explicitely
require word splitting (and also filename generation)

set -- $=LIST

and to also have filename generation:

set -- $=~LIST

(zsh also has a sh compatible mode in which splitting and
globbing is done implicitely, see also the SH_WORD_SPLIT and
GLOB_SUBST options).

See question 3.1 of zsh faq
http://www.faqs.org/faqs/unix-faq/shell/zsh/
http://zsh.sourceforge.net/FAQ/zshfaq03.html#l17

--
Stephane
Andreas Karrer

2004-07-09, 11:56 am

* familie oehler <oehlers@bluewin.ch>:

> or even svr4 implementation on amdahl, please copy the following script and
> send the output to oehlers@bluewin.ch. please make sure /bin/sh is a bourne-sh
> (linux is bash and not bourne).


/bin/sh on OSF/1^WDEC UNIX^WCompaq Tru64 UNIX behaves the same way as
Solaris' /bin/sh, e.g. "found only 6 token".

You could use /usr/xpg4/bin/sh on Solaris.

- Andi
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com