我正在尝试自动化(使用bash脚本)在JHFS+上创建macOS格式化的DMG文件。脚本应该能够接收用户提供的:
我使用了以下方法:
date
read -p "Enter the size of the DMG: " size
read -e -p "Enter the destination of the DMG: " dest
read -p "Enter the filesystem (HFS+,JHFS+,APFS,FAT32,ExFAT or UDF) :" fs
read -p "Enter the Volume name :" volname
read -p "Enter the name of the DMG:" name
hdiutil create -fs {"$fs"} -size "$size" -volname "{$volname}" "{$dest\/$name}"
exit问题是当脚本被执行时,大小被提到为"1g“(1GB),我得到以下错误:
hdiutil: create failed - Invalid argument改进脚本的建议是预先提出的welcome.Thanks :)
发布于 2019-03-21 17:10:07
变量周围的花括号{和}是错误的,转义斜杠\/不起作用。
我将$dest和$name更改为合并的$dest,并添加了默认值。对于大小,我为最常见的大小添加了一点提示。
#!/bin/bash
defaults=( 1g HFS+ "my volume" ~/Desktop/myvolume.dmg )
read -ep "Enter the size (??m|??g|??t) [${defaults[0]}] " size
read -ep "Enter the filesystem (HFS+, JHFS+, APFS, FAT32, ExFAT, UDF) [${defaults[1]}] " fs
read -ep "Enter the volume name [${defaults[2]}] " volname
read -ep "Enter the image destination [${defaults[3]}] " dest
hdiutil create -size "${size:-${defaults[0]}}" -fs "${fs:-${defaults[1]}}" -volname "${volname:-${defaults[2]}}" "${dest:-${defaults[3]}}"https://unix.stackexchange.com/questions/507713
复制相似问题