The first question:
echo 'abcd123' actually print
'abcd123\n' to stdout. And for
tr -c 'a-z' '0-9' the
-c option means complement of
'a-z' will be used for the translation, see man page of
There are many more character excluding 'a-z' correspond to '0-9', so the remaining character of
'abcd123\n', excluding lowercase character, that is
'123\n', will be translated to
'9999'. So the result is 'abcd9999', with on trailing '\n'.
The second question is much simple:
echo hello 1 char 2 next 4 print
hello 1 char 2 next 4\n to stdout. The
'tr -d -c '0-9 \n'' delete every complement of
'0-9' number and space character and '\n'.
That is why the remaining character contains numbers and spaces, and by the way a trailing '\n'.