• What does @{FOOBAR@a} mean? (bash)

    From John-Paul Stewart@21:1/5 to Kenny McCormack on Sat Apr 13 16:54:42 2024
    On 2024-04-13 4:35 p.m., Kenny McCormack wrote:
    Observe:

    $ unset FOOBAR
    $ echo ${FOOBAR@a}

    $ FOOBAR=
    $ echo ${FOOBAR@a}

    $ export FOOBAR
    $ echo ${FOOBAR@a}
    x
    $

    It seems that it prints "x" iff the variable has been exported.
    This works with any variable - the output is always "x" (iff it is exported).

    I can find no mention of this feature in "man bash". Note: I am not saying it isn't in there - just that I couldn't find it.

    Search the man page for 'Parameter transformation' and you'll find it.
    It's the last entry in the 'Parameter Expansion' section, just before
    'Command Substitution' if that makes it any easier to find.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to All on Sat Apr 13 20:35:27 2024
    Observe:

    $ unset FOOBAR
    $ echo ${FOOBAR@a}

    $ FOOBAR=
    $ echo ${FOOBAR@a}

    $ export FOOBAR
    $ echo ${FOOBAR@a}
    x
    $

    It seems that it prints "x" iff the variable has been exported.
    This works with any variable - the output is always "x" (iff it is exported).

    I can find no mention of this feature in "man bash". Note: I am not saying
    it isn't in there - just that I couldn't find it.

    Note that any other letter (such as "b") generates an error message if
    FOOBAR is non-empty:

    $ echo ${FOOBAR@b}

    $ FOOBAR=Test
    $ echo ${FOOBAR@b}
    bash: ${FOOBAR@b}: bad substitution
    $

    What is going on?

    --
    No, I haven't, that's why I'm asking questions. If you won't help me,
    why don't you just go find your lost manhood elsewhere.

    CLC in a nutshell.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Waitzmann@21:1/5 to All on Sat Apr 13 23:21:30 2024
    gazelle@shell.xmission.com (Kenny McCormack):
    Observe:

    $ unset FOOBAR
    $ echo ${FOOBAR@a}

    $ FOOBAR=
    $ echo ${FOOBAR@a}

    $ export FOOBAR
    $ echo ${FOOBAR@a}
    x
    $

    It seems that it prints "x" iff the variable has been exported.

    This works with any variable - the output is always "x" (iff it
    is exported).


    That's correct.


    I can find no mention of this feature in "man bash". Note: I am
    not saying it isn't in there - just that I couldn't find it.


    man -- 1 bash 2> /dev/null |
    sed -E -e '/\$\{[[:alpha:]]+@/,$p' -n

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Kenny McCormack on Sat Apr 13 22:14:27 2024
    On Sat, 13 Apr 2024 20:35:27 +0000, Kenny McCormack wrote:

    Observe:

    $ unset FOOBAR
    $ echo ${FOOBAR@a}

    $ FOOBAR=
    $ echo ${FOOBAR@a}

    $ export FOOBAR
    $ echo ${FOOBAR@a}
    x
    $

    It seems that it prints "x" iff the variable has been exported.
    This works with any variable - the output is always "x" (iff it is exported).

    I can find no mention of this feature in "man bash".
    [snip]
    What is going on?

    ${parameter@operator}
    Parameter transformation. The expansion is either a
    transformation of the value of parameter or information
    about parameter itself, depending on the value of
    operator. Each operator is a single letter:

    U The expansion is a string that is the value of
    parameter with lowercase alphabetic characters
    converted to uppercase.
    u The expansion is a string that is the value of
    parameter with the first character converted to
    uppercase, if it is alphabetic.
    L The expansion is a string that is the value of
    parameter with uppercase alphabetic characters
    converted to lowercase.
    Q The expansion is a string that is the value of
    parameter quoted in a format that can be reused as
    input.
    E The expansion is a string that is the value of
    parameter with backslash escape sequences expanded
    as with the $'...' quoting mechanism.
    P The expansion is a string that is the result of
    expanding the value of parameter as if it were a
    prompt string (see PROMPTING below).
    A The expansion is a string in the form of an
    assignment statement or declare command that, if
    evaluated, will recreate parameter with its
    attributes and value.
    K Produces a possibly-quoted version of the value of
    parameter, except that it prints the values of
    indexed and associative arrays as a sequence of
    quoted key-value pairs (see Arrays above).
    a The expansion is a string consisting of flag values
    representing parameter's attributes.
    k Like the K transformation, but expands the keys and
    values of indexed and associative arrays to
    separate words after word splitting.

    I don't know when it was introduced into bash. My version of bash
    (GNU bash, version 4.3.48(1)-release (x86_64-slackware-linux-gnu) )
    doesn't support it.

    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to oe.throttle@xoxy.net on Sat Apr 13 21:39:28 2024
    In article <838r1harhh.fsf@helmutwaitzmann.news.arcor.de>,
    Helmut Waitzmann <oe.throttle@xoxy.net> wrote:
    ...
    I can find no mention of this feature in "man bash". Note: I am
    not saying it isn't in there - just that I couldn't find it.

    So, what does it do?

    --
    The people who tell us to be proud of the white race are the ones who make
    us the most embarrassed by it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to lew.pitcher@digitalfreehold.ca on Sun Apr 14 01:02:38 2024
    In article <uvf043$33fov$1@dont-email.me>,
    Lew Pitcher <lew.pitcher@digitalfreehold.ca> wrote:
    On Sat, 13 Apr 2024 20:35:27 +0000, Kenny McCormack wrote:

    Observe:

    $ unset FOOBAR
    $ echo ${FOOBAR@a}

    $ FOOBAR=
    $ echo ${FOOBAR@a}

    $ export FOOBAR
    $ echo ${FOOBAR@a}
    x
    $

    It seems that it prints "x" iff the variable has been exported.
    This works with any variable - the output is always "x" (iff it is exported).

    I can find no mention of this feature in "man bash".
    [snip]
    What is going on?

    ${parameter@operator}

    Wow. Weird. Thanks.

    I wonder what the "flag values" are that you get with @a (my "x")...

    --
    Just like Donald Trump today, Jesus Christ had a Messiah complex.

    And, in fact, the similarities between the two figures are quite striking.
    For example, both have a ragtag band of followers, whose faith cannot be shaken.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to Kenny McCormack on Sun Apr 14 01:03:18 2024
    In article <uvf9ve$3oki0$1@news.xmission.com>,
    Kenny McCormack <gazelle@shell.xmission.com> wrote:
    ...
    I wonder what the "flag values" are that you get with @a (my "x")...

    I suppose "x" is for exported.

    --
    When I was growing up we called them "retards", but that's not PC anymore.
    Now, we just call them "Trump Voters".

    The question is, of course, how much longer it will be until that term is also un-PC.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From vallor@21:1/5 to Kenny McCormack on Sun Apr 14 02:11:29 2024
    On Sun, 14 Apr 2024 01:03:18 -0000 (UTC), gazelle@shell.xmission.com
    (Kenny McCormack) wrote in <uvfa0m$3oki0$2@news.xmission.com>:

    In article <uvf9ve$3oki0$1@news.xmission.com>, Kenny McCormack <gazelle@shell.xmission.com> wrote:
    ...
    I wonder what the "flag values" are that you get with @a (my "x")...

    I suppose "x" is for exported.

    I found the attributes in the man page under the entry
    for typeset/declare.

    "export" is like saying "declare -x".

    For fast access to the attributes: "help declare".

    (Thank you for the post, it taught me something.)

    --
    -v

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Popping Mad@21:1/5 to Lew Pitcher on Sun Apr 14 06:07:12 2024
    On 4/13/24 18:14, Lew Pitcher wrote:
    The expansion is a string consisting of flag values
    representing parameter's attributes.


    What does this mean?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lew Pitcher@21:1/5 to Popping Mad on Sun Apr 14 14:11:06 2024
    On Sun, 14 Apr 2024 06:07:12 -0400, Popping Mad wrote:

    On 4/13/24 18:14, Lew Pitcher wrote:
    The expansion is a string consisting of flag values
    representing parameter's attributes.


    What does this mean?

    bash expansion variables have various (and multiple) characteristics that govern how they work in expansions. You can have <<functions>> or <<non-functions>>, <<indexed arrays>> or <<associative arrays>> or <<integers>>, <<exported>> or <<not exported>>, etc.

    You can use the "typeset" builtin[1] to explicitly set these characteristics, or set them by your bash script actions.

    The "typeset" builtin can also tell you what those characteristics are for specific expansion variables.

    Apparently, bash has now added an expansion rule that /also/ reports on the characteristics of the expansion variable.


    [1] See bash(1) SHELL BUILTIN COMMANDS for more details

    HTH
    --
    Lew Pitcher
    "In Skills We Trust"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)