| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| X-SWARE-Spam-Status: | No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_PASS |
| X-Spam-Check-By: | sourceware.org |
| X-DKIM: | Sendmail DKIM Filter v2.6.0 mail-in-02.arcor-online.net A8DA63FE31B |
| Message-ID: | <49B2F8AC.7060201@arcor.de> |
| Date: | Sat, 07 Mar 2009 23:43:56 +0100 |
| From: | Dirk Fassbender <dirk DOT fassbender AT arcor DOT de> |
| User-Agent: | Thunderbird 2.0.0.19 (Windows/20081209) |
| MIME-Version: | 1.0 |
| To: | cygwin AT cygwin DOT com |
| Subject: | Re: problem under cygwin with sh, bash, ksh |
| References: | <200903060726 DOT 35848 DOT iamsamm AT sammiam DOT us> <49B29A55 DOT 1080005 AT sh DOT cvut DOT cz> |
| In-Reply-To: | <49B29A55.1080005@sh.cvut.cz> |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
--------------070209050701090506070308
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
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
--------------070209050701090506070308
Content-Type: text/plain;
name="pipe_read_test"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="pipe_read_test"
IyEvYmluL2tzaAojIS9iaW4vYmFzaAojIS9iaW4vcGRrc2gKClRFU1RWQVI9
IlZBTFVFIGJlZm9yIHNldHRpbmcgYSBkaWZmZXJlbmQgdmFsdWUgaW4gYSBz
dWIgc2hlbGwiCmVjaG8gIk9VVFNJREUgb2Ygc3ViIHNoZWxsLiBWYWx1ZSBv
ZiBcJHtURVNUVkFSfSBiZWZvcmUgc2V0dGluZyB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0iVmFs
dWUgYmVmb3JlIHBvcnRhYmxlIHdoaWxlIHJlYWQgbG9vcCIKZWNobyAiVmFs
dWUgb2YgXCR7VEVTVFZBUn0gYmVmb3JlIFJFQURJTkcgcG9ydGFibGUgaW4g
YSB3aGlsZSByZWFkIGxvb3A6ICR7VEVTVFZBUn0iYQppPTAKd2hpbGUgcmVh
ZCBURVNUVkFSOyBkbwogICAgZWNobyAiVmFsdWUgb2YgXCR7VEVTVFZBUn0g
YWZ0ZXIgUkVBRElORyBwb3J0YWJsZSBpbiBhIHdoaWxlIHJlYWQgbG9vcDog
JHtURVNUVkFSfSIKICAgIGk9JCgoIGkgKyAxICkpCglSRUFEVkFMVUVbJHtp
fV09JHtURVNUVkFSfQpkb25lIDw8RU5ECkZpcnN0IGxpbmUgdG8gcmVhZCBp
biB0aGUgd2hpbGUgcmVhZCBsb29wClNlY29uZCBsaW5lIHRvIHJlYWQgaW4g
dGhlIHdoaWxlIHJlYWQgbG9vcApFTkQKZWNobyAiVmFsdWUgb2YgXCR7VEVT
VFZBUn0gYWZ0ZXIgdGhlIGVuZCBvZiB0aGUgd2hpbGUgcmVhZCBsb29wOiAk
e1RFU1RWQVJ9IgplY2hvICJWYWx1ZSBvZiBcJHtSRUFEVkFMVUVbMV19IGFm
dGVyIHRoZSBlbmQgb2YgdGhlIHdoaWxlIHJlYWQgbG9vcDogJHtSRUFEVkFM
VUVbMV19IgplY2hvICJWYWx1ZSBvZiBcJHtSRUFEVkFMVUVbMl19IGFmdGVy
IHRoZSBlbmQgb2YgdGhlIHdoaWxlIHJlYWQgbG9vcDogJHtSRUFEVkFMVUVb
Ml19Igo=
--------------070209050701090506070308
Content-Type: text/plain; charset=us-ascii
--
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/
--------------070209050701090506070308--
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |