bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Assignment to RO variable


From: Greg Wooledge
Subject: Re: Assignment to RO variable
Date: Wed, 16 Aug 2023 07:14:00 -0400

On Tue, Aug 15, 2023 at 11:24:31PM -0500, Dennis Williamson wrote:
> Your use of colon as a comment character is confusing.

They're running with set -x, so presumably they used those : commands
to mark the set -x output with various labels.  Which seems nominally
clever, except they didn't *show* us the output.  Also, the example
is way more complicated than it needs to be, to the point where I
gave up trying to suss out what part of it they thought was behaving
incorrectly.

Compare with this example:


unicorn:~$ cat foo
#!/bin/bash

f() {
    local x=in_function_f
    echo "still in f"
}

readonly x=global
f
unicorn:~$ ./foo
./foo: line 4: local: x: readonly variable
still in f


As you stated, a variable that has been declared readonly at the global
scope is also considered readonly at every other scope.  This is the
intended behavior.

After the failed local variable assignment, the function continues
execution.  This is also the intended behavior, as this example does
not use any of the set -e variants.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]