[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: command substitution subshell exits when assigning to readonly varia
From: |
Zachary Santer |
Subject: |
Re: command substitution subshell exits when assigning to readonly variable |
Date: |
Thu, 19 Oct 2023 09:02:22 -0400 |
On Wed, Oct 18, 2023 at 11:23 AM alex xmb sw ratchev <fxmbsw7@gmail.com>
wrote:
> oh uhm sorry , to tell in short .. it looks for ending ' r ' for readonly
> in declare -p _var_ output
>
Here's a better way to do that:
$ unset var
$ var='word'
$ if [[ ${var@a} == *'r'* ]]; then
> printf '%s\n' "var is readonly"
> else
> printf '%s\n' "var isn't readonly"
> fi
var isn't readonly
$ readonly var
$ if [[ ${var@a} == *'r'* ]]; then
> printf '%s\n' "var is readonly"
> else
> printf '%s\n' "var isn't readonly"
> fi
var is readonly
>From the manual:
Parameter Expansion
[...]
${parameter@operator}
Parameter transformation. [...]
a
The expansion is a string consisting of flag values representing
parameter's attributes.
Zack