bash - magic bytes (or removing latest newlines from being piped) -
as messing multipart messages encountered strange behavior evaluating content length of multipart message bodies.
long story short. can broke down newlines being piped.
$ a="x"; b="y" $ echo -e "${a}" | wc -c 2 # strange, shouldn't single byte? $ echo -e "${b}" | wc -c 2 # @ point 1 guess sum **4**, not $ echo -e "${a}${b}" | wc -c 3 $ echo -e "${a}${b}" | hexdump -c 00000000 78 79 0a |xy.| 00000003
is there possibility avoid magic/invisible byte being piped or - if not possible - @ least removed?
thanks in advance.
the magic character you're referring to, newline character \n
. newline tells terminal emulator you're running — guessed — print newline!
echo
default appends newline end of string, string doesn't end on same line prompt.
echo
can passed -n
, prevents appending newline end of string. use printf
command not append newline default.
i suggest printf
on echo
, there many portability problems echo
now-a-days.
so, in end, sample command like:
printf "${a}" | wc -c
or echo
:
echo -en "${a}" | wc -c
Comments
Post a Comment