阅读:非法选项-d [英] read: Illegal option -d
问题描述
这是我脚本中令人讨厌的部分:
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
和错误:
read: 175: Illegal option -d
我在所有地方都使用这个读-d,它工作正常.不知道为什么现在不开心.我在Ubuntu 10.10上运行脚本
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
修正?解决方法?
推荐答案
如果运行sh
,然后尝试执行该命令,则会得到:
If you run sh
and then try that command, you get:
read: 1: Illegal option -d
如果您仍在bash
中进行此操作,则效果很好.
If you do it while still in bash
, it works fine.
因此,我推断您的脚本 not 在bash
下运行.
I therefore deduce that your script is not running under bash
.
确保您的脚本以以下行开头:
Make sure that your script begins with the line:
#!/usr/bin/env bash
(或等效名称),以便正确的shell运行脚本.
(or equivalent) so that the correct shell is running the script.
或者,如果您不能执行此操作(因为该脚本不是bash
脚本),则请注意-d
是bash
功能,并且可能在其他Shell中不可用.在这种情况下,您将需要寻找另一种方法.
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.
这篇关于阅读:非法选项-d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!