problem under cygwin with sh, bash, ksh
Dirk Fassbender
dirk.fassbender@arcor.de
Sat Mar 7 22:44:00 GMT 2009
Václav Haisman schrieb:
> Hubert Samm wrote, On 6.3.2009 14:26:
>> Hi All... I've searched and found nothing.... this script runs just fine on
>> AIX, Solaris, and Linux, but under cygwin, the array VALUE prints only
>> blanks.. has anyone else run into this... I've tried a bunch of different
>> things around typecast, etc, but it looks like VALUE is local in the table_it
>> function... any thoughts???
>> [...]
> Have you tried debugging it using the -x switch to see what is going on?
> Simple test case of setting VALUE[0]=$1 and then echoing "${VALUE[0]}" does
> print what I give it, using bash.
>
> --
> VH
>
> --
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
> Problem reports: http://cygwin.com/problems.html
> Documentation: http://cygwin.com/docs.html
> FAQ: http://cygwin.com/faq/
>
>
This is a problem with portable script programming between different shells.
Some explanations:
Shell Versions used:
AIX uses as the default sh shell a ksh Version 88.
HP-UX uses as the default sh shell a ksh Version 88.
Solaris uses as the default sh shell a non posix compatible shell.
The ksh on Solaris is mostly a Version 88, opensolaris uses a ksh
Version 93.
Linux uses as the default sh shell a bash.
Older Linux versions uses a pdksh as a replacement for the ksh shell.
Newer Linux versions uses a ksh Version 93.
Cygwin uses as the default sh shell a bash
Cygwin uses the a pdksh as a replacement fir the ksh shell.
Setting variables and sub shells.
If you set a variable in a sub shell, this variable usable in the
calling shell. You can execute commands in a sub shell with the
following syntax (list).
The different shell executed the commands in a pipe in a different
manner. The shells uses internally sub shells to execute the different
commands of a pipe line.
command1 | command2 | command3
is executed in this order in the different shells.
bash : command1 | (command2) | (command3)
pdksh : command1 | (command2) | (command3)
ksh : (command1) | (command2) | command3
So only in a ksh it is possible to set a variable in the last command of
a pipeline and uses this variable later in the shell script.
A short example script for bash, pdksh and ksh is attached.
It includes a in all 3 shell working solution at the end.
So the solution for your problem is to use a ksh version 93 on cygwin
or rewrite your code more portable.
You can download a version of ksh version 93 from http://www.kornshell.com/
Regards
Dirk
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pipe_read_test
URL: <http://cygwin.com/pipermail/cygwin/attachments/20090307/cc0f6fc0/attachment.ksh>
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list