开发者

read: Illegal option -d

Here is开发者_如何学JAVA 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?


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.


The -d option to read is a feature unique to bash, not part of the POSIX standard (which only specifies -r and -p options to read). When you run your script with sh on Ubuntu, it's getting run with dash, which is a POSIX shell, and not bash. If you want the script to run under bash then you should run it with bash, or give it a #!/bin/bash shebang. Otherwise, it should be expected to run under any POSIX sh.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜