阅读:非法选项-d [英] read: Illegal option -d

查看:99
本文介绍了阅读:非法选项-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脚本),则请注意-dbash功能,并且可能在其他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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆