Subject: piperead arithmentic

From: Elliot Sowadsky <[email-masked]>
Date: Sun, 23 Mar 2003 18:30:32 -0800 (PST)

2.5.6 on solaris 5.8

piperead example in faq gives shell syntax error

    AddToFunc   CenterWindow
    + I ThisWindow Piperead "echo Move \
      $(( $[vp.width]/2-$[w.width]/2 ))p \
      $(( $[vp.height]/2-$[w.height]/2 ))p"

sh complains about missing (

Actually i'm trying to calculate which horizontal pager window i'm in
when i click on it.

Thanx
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Mon, 24 Mar 2003 10:33:07 +0100

> Actually i'm trying to calculate which horizontal pager window i'm in

Look like the solaris /bin/sh does not know the "$(( ... ))"
syntax.  What is the most portable syntax for arithmetic
expansion?

Bye

Dominik ^_^  ^_^

---

From: Marcin Pawlik <[email-masked]>
Date: Mon, 24 Mar 2003 11:20:42 +0100

On Mon, Mar 24 at 10:33, Dominik Vogt wrote:
> Look like the solaris /bin/sh does not know the "$(( ... ))" syntax.  

Checked in 5.9 and it really doesn't.

> What is the most portable syntax for arithmetic expansion?

Probably using (external) expr, but AFAIR the $(( )) arithmetic
expansion should be supported in all POSIX compliant shells.

Regards,

-- 
Marcin Pawlik

---

From: Dan Espen <[email-masked]>
Date: Mon, 24 Mar 2003 08:40:15 -0500

> expansion should be supported in all POSIX compliant shells.

I checked, that notation is part of the POSIX requirement for shells.

This is what the Solaris 8 man page says about popen (what PipeRead uses):

popen:

     The environment of the executed command  will  be  as  if  a
     child  process  were  created  within the popen() call using
     fork(2). If  the  application  is  standard-conforming  (see
     standards(5)), the child is invoked with the call:

          execl("/usr/bin/ksh", "ksh", "-c", command, (char *)0);

     otherwise, the child is invoked with the call:

          execl("/usr/bin/sh", "sh", "-c", command, (char *)0);

So, our man page statement about PipeRead using /bin/sh is not
strictly true on Solaris.

I built fvwm with gcc and arithmetic in PipeRead appears to work
for me.

The standards(5) man page is a bit confusing, but I think it
says you should use c89 instead of cc or define
_POSIX_C_SOURCE=199506L
when using Sun's compiler.

-- 
Dan Espen                           E-mail: [email-masked]

---

From: Danek Duvall <[email-masked]>
Date: Mon, 24 Mar 2003 12:31:23 -0800

>           execl("/usr/bin/ksh", "ksh", "-c", command, (char *)0);

This is actually a bug in Solaris 8, which is fixed with patch 108827-40
(108828-40 for x86), so that the posix shell /usr/xpg4/bin/sh is run
instead.  This is fixed in Solaris 9 and up without a patch.

Just to add to the fun, the man page in Solaris 9 says it runs
/usr/xpg4/bin/ksh -- it's wrong.

Danek

---

From: Dan Espen <[email-masked]>
Date: Mon, 24 Mar 2003 15:43:58 -0500

> instead.  This is fixed in Solaris 9 and up without a patch.

On my Solaris 8 system, /usr/xpg4/bin/sh is a link to /usr/bin/ksh
which happens to the the same as /bin/ksh.

The "sh" man page confirms this:

     The /usr/xpg4/bin/sh utility is identical  to  /usr/bin/ksh.

> /usr/xpg4/bin/ksh -- it's wrong.

I think someone is confused.

---

From: Danek Duvall <[email-masked]>
Date: Mon, 24 Mar 2003 12:49:59 -0800

>      The /usr/xpg4/bin/sh utility is identical  to  /usr/bin/ksh.

Okay.  This is different in Solaris 9, and possibly in Solaris 8 with
the patch I mentioned.  They are separate binaries, and the man page
notes that they're mostly the same except in some places mentioned in
the ksh man page (which happen to be in arithmetic expansion, as it
turns out).

> I think someone is confused.

Looks like it.

Danek

---

From: Dan Espen <[email-masked]>
Date: Mon, 24 Mar 2003 16:18:59 -0500

> the ksh man page (which happen to be in arithmetic expansion, as it

I found a Solaris 9 system.
Assuming the man page meant to say they run /usr/xpg4/bin/sh,
here's Solaris 9 man page for sh:

     The /usr/xpg4/bin/sh utility is a standards compliant shell.
     This  utility  provides  all  the  functionality  of ksh(1),
     except in cases discussed in  ksh(1)  where  differences  in
     behavior exist.

But when I look at the ksh description, this is the difference:

  /usr/bin/ksh and /usr/bin/rksh treat prefix 0  through
  9 as decimal constants. See the examples below.

     Command               Result in /bin/ksh   Result in /usr/xpg4/bin/sh
     echo $((010+10 ))     20                   18
     echo $((010+10 ))     29                   error
     [ 10 -le $((011)) ]   true                 false

Which doesn't make a lot of  sense since the  first 2 examples are the
same,  but  I don't   think  the difference  caused the  error message
originally reported.

I checked /usr/xpg4/bin/sh, it can at least evaluate simple expressions.

---

From: Michael Han <[email-masked]>
Date: Mon, 24 Mar 2003 13:25:26 -0800

> same,  but  I don't   think  the difference  caused the  error message

I'm guessing that's a typo and that the second command should read:

echo $((019+10 ))

The output makes sense in that case. I guess like perl, 0-prefixing in
XPG4 shell is supposed to be octal.

I have no idea what this thread is about. I just like making fun of
/usr/xpg4 on Solaris...
-- 
[email-masked]                            http://www.mikehan.com/
coffee achiever                              San Francisco, California
"If you lend me some money, it'll be my treat."
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Danek Duvall <[email-masked]>
Date: Mon, 24 Mar 2003 13:48:38 -0800

> I'm guessing that's a typo and that the second command should read:

Yup.  I filed a bug against that, as well as against the typo in the
popen(3c) page.

> I have no idea what this thread is about. I just like making fun of

Then you'll love /usr/xpg6 ... ;-)

Danek

---

From: Dan Espen <[email-masked]>
Date: Mon, 24 Mar 2003 17:02:16 -0500

> Yup.  I filed a bug against that, as well as against the typo in the

How about a bug report for the lack of posix compliance in /bin/sh?
Or is it a compiler issue or popen?

Both my HP and AIX systems have no trouble with arithmetic in
/bin/sh.  Solaris seems to be the odd man out.

---

From: Danek Duvall <[email-masked]>
Date: Mon, 24 Mar 2003 14:20:23 -0800

> Or is it a compiler issue or popen?

/bin/sh (and all the other utilities in /bin) is not expected to be
posix compliant.  If you want posix compliance, you should be running
the versions in /usr/xpg4/bin instead, either directly, or by putting
that first in your $PATH.

There was a bug filed for exactly this about five years ago, which was
closed because it was presumed that too many scripts depend on the
particular behaviors of /bin/sh to make the transition worthwhile.  I
don't think there's any way to make this change and preserve
compatibility for everyone who expects it.

> /bin/sh.  Solaris seems to be the odd man out.

/bin/sh on Solaris is a pretty sad program, and really (in my opinion,
not Sun's) shouldn't be used.  Either use ksh for interactive stuff and
personal scripts, or use the posix-flavored utilities in /usr/xpg4.
Which means that you'd have to parametrize the path to the shell with
configure, but you already do that for perl, so it's more of an
annoyance than a difficult problem.

Danek