zsh-workers
 help / color / mirror / code / Atom feed
* Read-only variables in emulation mode
@ 2013-12-16 19:10 Øystein Walle
  2013-12-16 19:40 ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Øystein Walle @ 2013-12-16 19:10 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-06-16 21:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-16 19:10 Read-only variables in emulation mode Øystein Walle
2013-12-16 19:40 ` Bart Schaefer
2013-12-18  6:36   ` Bart Schaefer
2013-12-18 19:28     ` Peter Stephenson
2013-12-19  7:57       ` Bart Schaefer
2015-06-16  0:10         ` Mikael Magnusson
2015-06-16  3:24           ` Bart Schaefer
2015-06-16  6:24             ` Mikael Magnusson
2015-06-16 15:54               ` Bart Schaefer
2015-06-16 21:06                 ` Mikael Magnusson
2015-06-16 19:05             ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).