current code:
echo -n "password: "
read -es password
echo -n "ok"
behavoir in linux:
password: ok
Can we make it like:
password:
ok
thanks, wxie
The following will work:
read -p "password: " -es password
echo
echo "ok"
Maybe:
read -p "password: " -es password
printf "\n ok \n"
If you want a newline before the OK, this should do it:
echo -e "\nok"
The -e
enables interpretation of the backslash codes.
From echo's man page: -n do not output the trailing newline
. Try it without the option.
We can use \n
as a line separator in printf
, there is an extra line for padding after "ok" which you can remove
printf "password: " && read -es password && printf "\n\nok\n"
If you are saving a password this way it would still be contained in the variable $password
in plain text, the string below would print it openly.
printf "$password"
Your code sample uses echo
and should be using printf
, there are articles on echo's POSIX compliance, echo
could work like Greg Tarsa points out, but not all versions are built with switch options like -e
or -n
.
I find it readable to use printf
, also other "languages" have similar commands such as PRINT, print, println, print() and others.
If you need to use echo you could
echo -n "password: " && read -es password && echo -e "\nok\n"