Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hdiutil working in terminal window but not in shell script

I am using using hdiutil to mount a sparseimage file and it works fine when I type the command into terminal but when I try to run it as a shell script it gives a error.

Here is the code:

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

This is the error:

hdiutil: attach failed - Authentication error

I am sure that the password is correct. Can anyone tell me what is wrong?

like image 975
user2189362 Avatar asked Sep 29 '13 23:09

user2189362


1 Answers

The EXAMPLES section of the hdiutil documentation recommends using printf for this rather than echo -n.

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

If you are testing against 10.9 betas, do make sure to test with both the very latest version and with 10.8. I only bring this up because I have encountered some STDIN-related bugs with early version of 10.9.

like image 71
Rob Napier Avatar answered Nov 02 '22 23:11

Rob Napier