hdiutil prints invisible characters for its devnode output

This script from man hdiutil no longer works:

devnode=$(hdiutil attach -nomount ram://102400)
newfs_hfs “$devnode”
mount -t hfs “$devnode” /path/to/ramdisk

because $devnode contains spaces and tabs!!

$ hdiutil attach -nomount ram://1 | xxd   
00000000: 2f64 6576 2f64 6973 6b34 2020 2020 2020  /dev/disk4      
00000010: 2020 2020 0920 2020 2020 2020 2020 2020      .           
00000020: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000030: 2020 2020 090a   

# remember to clean up afterwards
$ hdiutil detach /dev/disk4

Please properly quote your variables in CI test scripts to catch such regression. It could pass because unquoted expansion of $devnode undergoes word splitting after the variable is substituted, removing the trailing whitespaces.

FB20303191

Thanks for filing FB20303191.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

hdiutil prints invisible characters for its devnode output
 
 
Q