Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Read-only variables in emulation mode
- X-seq: zsh-workers 32134
- From: Øystein Walle <oystwa@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Read-only variables in emulation mode
- Date: Mon, 16 Dec 2013 20:10:49 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=M3f2yfa7+Xa9vVVOGswCRbUQXF8YXXQGynv1fWRjfZ8=; b=Hhggagm/5j1SzxL3eotDbvutS/7m40zliMgSufv2KeLdKa1LqHABfT8872I277834g hfUg8S5Jw/pjvZiteJ6CgHPHjrOfwp4fcsZYGBCHdUVysv7F7QgAt7L57CAOMd11QV9G g9hI5FxkHtf+okrJ/YQOe//VZA79uro+kFiMmrK+5cpUs6Qq6VOuuSz5JZGKscL2qS/G HxCr3budUaJzLhfrU9FDsPiQVBTP33k70CK1qbfzhVU3YcRgej7WdFtuch33FLoswnJC GarPVdDzhcajBba2SnWG8dKI6q6FQvazsZaL0gnwabhxMDDriQPRf8V0AA2n7q4pAOfX vlEQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Hi,
Consider the following:
emulate sh -c '
some_name() {
status=world
echo "hello $status"
}
some_name
'
Running it gives:
some_name:1: read-only variable: status
This is a problem if you source a "library" meant to be used by
different versions of different shells:
$ cat =git-example
#!/bin/zsh
emulate sh -c '
. git-sh-setup
'
...
require_work_tree
...
$ git example
die_with_status:1: read-only variable: status
A common idiom in (ba)sh scripting is to use _ as a throwaway in a
while-read loop:
while read -r col1 _ col2; do
echo "col1 = $col1 and col2 = $col2"
done < three-columns.txt
This also fails with an equivalent message when used in sh emulation.
Is it fixable? (Is the general opinion that it needs fixing?). I
assume status and _ are meant to be writable in POSIX shells.
I suppose an idea would be for various variables to be writable within
emulate -c '...' and later in the functions defined therein. How this
would affect the rest of the shell is hard to say for me.
In the mean time, is there any way around it?
Thanks
Øsse
Messages sorted by:
Reverse Date,
Date,
Thread,
Author