[Top][All Lists]

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

bug#26491: date and echo using with underscore

From: Assaf Gordon
Subject: bug#26491: date and echo using with underscore
Date: Fri, 14 Apr 2017 11:50:12 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

tag 26491 notabug
close 26491

Hello Edmond,

On 04/14/2017 02:36 AM, Edmond Yuen wrote:
> echo $D_$i

As others have replied (and thanks to all who replied),
an underscore character is valid part of a shell variable,
thus the shell tries to use the content of the variable "D_" - which is

This is part of the POSIX standard for shell variable expansion.
Specifically here:


   2.6.2 Parameter Expansion
   "If the parameter name or symbol is not enclosed in braces, the
    expansion shall use the longest valid name (see the Base
    Definitions volume of IEEE Std 1003.1-2001, Section 3.230, Name),
    whether or not the symbol represented by that name exists."

And "Section 3.230, Name" says:

   "In the shell command language, a word consisting solely of
    underscores, digits, and alphabetics from the portable character

This is not a bug in date or echo (or a bug at all),
and I'm closing this bug. Discussion can continue by replying to this

To detect and fail early when undefined variables are used,
you can optionally enable "-u" in your shell scripts:

    set -u
    echo A=$A
    echo A_=$A_

And the shell will terminate the script with:

    $ ./test.sh
    test.sh: 5: test.sh: A_: parameter not set

 - assaf

reply via email to

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