I want the read function to print anything but the new line when using in Bash script.
I tried the following code, but it does not help. It still prints the new line.
Minimal reproducing code:
#!/bin/bash
stty -echonl
read -e entered
PS. I know I could read characters one by one using read -n1, but this is not the way I would want to use.
readcommand does not print anything, it just reads. If yourreadprints something then it is not the bash builtinread. What do you see if you typecommand -V read?read is a shell builtin. How to use Bash builtintread?read -n1(or, even better,read -rsN1)?I want the read function to print anything but the new linesincereaddoesn't print anything. I wonder if in your real code you have a subsequent line likeecho "$entered"that's printing a newline and you think thatenteredcontains the newline? Please show a minimal reproducible example that we can copy/paste/execute to reproduce whatever problem you're asking for help with.read x <<<7then hit Enter. Did you see anything other than theread x <<<7that you typed displayed on your terminal? No becausereaddoesn't print anything.