Can I use read to capture the \n \012 or newline character?
Define test function:
f() { read -rd '' -n1 -p "Enter a character: " char &&
printf "\nYou entered: %q\n" "$char"; }
Run the function, press Enter:
$ f;
Enter a character:
You entered: ''
Hmmm. It's a null string.
How do I get my expected output:
$ f;
Enter a character:
You entered: $'\012'
$
I want the same method to be able to capture ^D or \004.
If read can't do it, what is the work around?
I'm interested in how to do this in both bash and POSIX sh.