Hdiutil works in a terminal window, but not in a shell script

I use hdiutil to mount the sparseimage file, and it works great when I type the command into the terminal, but when I try to run it as a shell script, it gives an error.

Here is the code:

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

This is mistake:

hdiutil: attach failed - Authentication error

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

+4
source share
1 answer

In the EXAMPLES section of the document, hdiutilit is recommended to use printffor this, and not 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. , , STDIN, 10.9.

+7

All Articles