本文介绍了击“读”命令无法在Mac接受-i参数。任何替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,我的工作Ubuntu的机器上工作得很好,但是当我尝试和我的Mac OSX 山狮笔记本电脑上运行它黯然打破。杀死它的线路是这样的:

I have a bash script that works fine on my work Ubuntu machine, but sadly breaks when I try and run it on my Mac OSX Mountain Lion laptop. The line that kills it is this:

while [[ -z "$SSHFS_PATH" ]] ; do
  read -e -p "Please enter the path on which to mount your file system: `echo -e $'\n > '`" -i "~/aws-dev" SSHFS_PATH;
done

它抛出这个错误:

It throws out this error:

-bash: read: -i: invalid option
read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]

因此​​,似乎读命令的OSX版本不接受 -i ,这是用来显示的默认值。为什么?而且可以做些什么来解决这个问题?

So it seems the OSX version of the read command doesn't accept -i, which is used to suggest default values. Why? And what can be done to fix this?

感谢:)

推荐答案

的Mac OS X 10.7狮子(以及在此日期都比较新的版本,以及由于@kojiro)附带庆典3.2 ,而读-i 的bash 4.0-α(见的)。

Mac OS X 10.7 Lion (and to this date all more recent versions as well, thanks @kojiro) ships with bash 3.2 whereas read -i was introduced with bash 4.0-alpha (see the ChangeLog).

您可以安装庆典使用或提供非readline的默认值自己,如:

You can either install a more recent version of bash using homebrew or provide a non-readline default value yourself, e.g.

read -p "Path? (default: /bar): " var
[ -z "${var}" ] && var='/bar'

这篇关于击“读”命令无法在Mac接受-i参数。任何替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 08:46