linux - bash - read: Illegal option -n

on Ubuntu , I try to pause a bash shell script

!#/bin/bash
...
read -n 1 -p"pause"

I have seen that syntax everywhere so I don't understand why is it not working

and I get this error

./build.sh: 14: read: Illegal option -n

what I also don't understand is that in the read man, there are no -n -p options

are there 2 different read commands in linux ?

sheers

1

1 Answer

read is a bash builtin, that has a -n option.

You are likely running dash which is a simpler shell, where read -n elicits that very error message.

Note that your "shebang" is wrong (!# instead of #!) so you may not be running your script with bash as you expect. In Ubuntu, the default shell (/usr/bin/sh or /bin/sh) is a soft link to dash.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like