【问题标题】:hdiutil working in terminal window but not in shell scripthdiutil 在终端窗口中工作,但不在 shell 脚本中
【发布时间】:2013-10-05 17:56:01
【问题描述】:

我正在使用 hdiutil 挂载一个稀疏图像文件,当我在终端中键入命令时它工作正常,但是当我尝试将它作为 shell 脚本运行时它会出错。

代码如下:

echo -n 'password' | hdiutil attach -stdinpass file.sparseimage

这是错误:

hdiutil: attach failed - Authentication error

我确定密码正确。谁能告诉我怎么了?

【问题讨论】:

  • 如果 shell 脚本使用 sh(这是 OS X 中 bash 的 POSIX 兼容版本),xpg_echo 默认启用,例如 echo -n password 打印 @987654327 @ 带换行符。
  • -n 与否无关紧要。问题是 -stdinpass 似乎不适用于 echo。

标签: macos bash shell unix terminal


【解决方案1】:

hdiutil 文档的示例部分建议为此使用 printf 而不是 echo -n

 Creating an encrypted single-partition image without user interaction:
       printf pp|hdiutil create -encryption -stdinpass -size 9m sp.dmg

如果您要针对 10.9 测试版进行测试,请务必同时使用最新版本和 10.8 进行测试。我之所以提出这个问题,是因为我在 10.9 的早期版本中遇到了一些与 STDIN 相关的错误。

【讨论】:

    猜你喜欢
    • 2022-01-27
    • 2018-05-27
    • 1970-01-01
    • 2016-09-15
    • 2012-11-05
    • 2014-06-27
    • 2019-10-30
    • 1970-01-01
    • 2017-01-17
    相关资源
    最近更新 更多