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' ]]



Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to