bourne-sh behavior
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > bourne-sh behavior




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    bourne-sh behavior  
familie oehler


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-04-04 08:22 AM

hi

i was programing installation procedures based on bourne-sh, sed, awk and al
l
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 you
r
loosing orientation.

i created a verry simple script testing the problem and showing the testsuit
e.
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







[ Post a follow-up to this message ]



    Re: bourne-sh behavior  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-04-04 10: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 i
s
> 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 t
he
> real bourne-sh by contacting other unix poeple.
>
> the problem is simple: empty tokens are ignored. no other parsing algoryth
m
> 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 y
our
> 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 ***





[ Post a follow-up to this message ]



    Re: bourne-sh behavior  
Heiner Steven


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-04-04 10:52 PM

familie oehler wrote:

[...]
> the problem is simple: empty tokens are ignored. no other parsing algoryth
m 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 y
our
> loosing orientation.
>
> i created a verry simple script testing the problem and showing the testsu
ite.
> 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 an
d
> send the output to oehlers@bluewin.ch. please make sure /bin/sh is a bourn
e-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/





[ Post a follow-up to this message ]



    Re: bourne-sh behavior  
Michael Tosch


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-05-04 10: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 i
s
> 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 t
he
> real bourne-sh by contacting other unix poeple.
>
> the problem is simple: empty tokens are ignored. no other parsing algoryth
m 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 y
our
> loosing orientation.
>
> i created a verry simple script testing the problem and showing the testsu
ite.
> 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 an
d
> send the output to oehlers@bluewin.ch. please make sure /bin/sh is a bourn
e-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.






[ Post a follow-up to this message ]



    Re: bourne-sh behavior  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-09-04 04:56 PM

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





[ Post a follow-up to this message ]



    Re: bourne-sh behavior  
Andreas Karrer


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-09-04 04:56 PM

* familie oehler <oehlers@bluewin.ch>:

> or even svr4 implementation on amdahl, please copy the following script an
d
> send the output to oehlers@bluewin.ch. please make sure /bin/sh is a bourn
e-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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:36 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register