---------- Forwarded message ---------
From: Dennis Williamson <[email protected]>
Date: Thu, Oct 26, 2023 at 12:09 PM
Subject: Re: Strange results
To: Victor Pasko <[email protected]>
echo "echo11 ${ASCII_SET:-10:1}"echo "echo11 ${ASCII_SET:-10:1}"
On Thu, Oct 26, 2023 at 9:54 AM Victor Pasko <[email protected]> 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.