Read input without echoing is not working (bash Shell Script)

Viewed 906

"-s" switch is not working bash shell script. It throws error without prompting for the password.

Using: Ubuntu 16.04.6 LTS

Am i missing anything?

#!/bin/bash

echo "Enter password"
read -s password
echo "password:" $password

Enter password test.sh: 4: read: Illegal option -s password:

1 Answers

You are running the script with sh, not bash which provides the functionality in question. Either invoke the script directly with bash:

bash test.sh

Or make the file executable so the interpreter will read your shebang:

chmod +x test.sh    # only required once
./test.sh

The .sh extension is unnecessary unless you are running actual POSIX shell scripts in certain special directories.

Related