Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read: Illegal option -d

Tags:

bash

Here is the offending part of my script:

read -d '' TEXT <<'EOF'
Some Multiline
text that
I would like
in 
a 
var
EOF

echo "$TEXT" > ~/some/file.txt

and the error:

read: 175: Illegal option -d

I use this read -d all over the place and it works fine. Not sure why its not happy now. I'm running the script on Ubuntu 10.10

Fixes? Workarounds?

like image 406
mikewilliamson Avatar asked Feb 23 '11 23:02

mikewilliamson


1 Answers

If you run sh and then try that command, you get:

read: 1: Illegal option -d

If you do it while still in bash, it works fine.

I therefore deduce that your script is not running under bash.

Make sure that your script begins with the line:

#!/usr/bin/env bash

(or equivalent) so that the correct shell is running the script.

Alternatively, if you cannot do that (because the script is not a bash one), just be aware that -d is a bash feature and may not be available in other shells. In that case, you will need to find another way.

like image 91
paxdiablo Avatar answered Nov 15 '22 15:11

paxdiablo