bug-bash
[Top][All Lists]
Advanced

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

Fwd: Strange results


From: Dennis Williamson
Subject: Fwd: Strange results
Date: Thu, 26 Oct 2023 12:09:53 -0500

---------- Forwarded message ---------
From: Dennis Williamson <dennistwilliamson@gmail.com>
Date: Thu, Oct 26, 2023 at 12:09 PM
Subject: Re: Strange results
To: Victor Pasko <victor.pasko@gmail.com>


echo "echo11 ${ASCII_SET:-10:1}"echo "echo11 ${ASCII_SET:-10:1}"

On Thu, Oct 26, 2023 at 9:54 AM Victor Pasko <victor.pasko@gmail.com> wrote:

> Hi,
>
> echo9 u
> echo10 u
> And the most strange result
> echo11
>
>  
> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
>
> --
>
> -- PSK
>

echo "echo9 ${ASCII_SET:$((a-10)):1}"
echo "echo10 ${ASCII_SET:$((-10)):1}"

Both of these say "output the character that's 10th from the end" which is
"u". What did you expect it to output?

echo "echo11 ${ASCII_SET:-10:1}"

This says, according to the man page:

       ${parameter:-word}
              Use Default Values.  If parameter is unset or null, the
expansion of word is substituted.  Otherwise, the value of parameter is
substituted

which means output "10:1" if ASCII_SET is unset or null. Since it isn't,
the contents of that variable are output giving you a long sequence of
ASCII characters.

-- 
Visit serverfault.com to get your system administration questions answered.


-- 
Visit serverfault.com to get your system administration questions answered.


reply via email to

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