2013-09-29 52 views
4

我使用hdiutil裝入sparseimage文件,當我將命令鍵入終端時它工作正常,但當我嘗試將它作爲shell腳本運行時,它會給出錯誤。hdiutil在終端窗口中工作,但不在shell腳本中

下面是代碼:

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

這是錯誤:

hdiutil: attach failed - Authentication error 

我確信密碼正確。誰能告訴我什麼是錯的?

+0

如果shell腳本使用'sh'(這是OS X中'bash'的POSIX兼容版本),'xpg_echo'默認啓用,例如'echo -n password'打印'-n password '用換行符。 – user495470

+0

-n或不應該太重要。問題是-stdinpass似乎不能與echo一起工作。 –

回答

7

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 beta版本,請確保使用最新版本和10.8進行測試。我只提出這個問題,因爲我在10.9的早期版本中遇到了一些與STDIN相關的bug。

相關問題