[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: BUG?: (or what's going on?) test for NL == NL fails (bash-4.3.39(3)-
From: |
Charles Daffern |
Subject: |
Re: BUG?: (or what's going on?) test for NL == NL fails (bash-4.3.39(3)-release) |
Date: |
Sun, 2 Aug 2015 22:15:45 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 |
On 02/08/15 21:30, Linda Walsh wrote:
> Am just looking for an efficient way to test for 0x0a
> as last char in a var, ... after another 20 minutes of
> trying things at random, found this:
>
> > printf "%d\n" "'${a:0-1:1}'"
> 10
>
> Oddly, the final single quote in the string seems unnecessary.
> But that (or into a var: printf -v var) both work...but I
> feel a bit contorted trying so many odd ways to get something
> that I thought would be simple, to work.
Most of the problems here are due to the use of command substitution (as
I mentioned in an earlier response).
The ways I would go about checking for a newline at the end of a string are:
[ "$var" != "${var%$'\n'}" ]
or
[[ $var = *$'\n' ]]
signature.asc
Description: OpenPGP digital signature