Vicky
Vicky

Reputation: 489

read: Illegal option -s in shell scripting

I tried running this code:

#!/bin/bash
read -s "Password: " password

With command:

run sh init.sh

it throws an error: read: Illegal option -s. Any help.

Upvotes: 12

Views: 16935

Answers (1)

Geoff Nixon
Geoff Nixon

Reputation: 4994

I take it you're using Debian/Ubuntu, or a BSD-derivative?

When you execute a command like run sh init.sh (although I'm not myself familiar with this run command) you are overriding the #!/bin/bash shebang. In your case sh is a strictly compliant POSIX shell like dash, where, in fact, the only argument to read that is not an extension is -r.

So maybe you'd want to use run bash init.sh instead?

Upvotes: 18

Related Questions