timsutton / osx-vm-templates

macOS templates for Packer and VeeWee.
MIT License
1.12k stars 248 forks source link

Fix stat file path to absolute file path #50

Closed zchee closed 8 years ago

zchee commented 8 years ago

I as much as possible to follow to Linux (also GNU), I have installed coreutils with --with-default-names in Homebrew. Also, stat is shell built-in command of zsh.

If using the stat of coreutils or zsh,

# in zsh built-in stat,
stat: bad file descriptor
# in coreutils stat,
stat: cannot read file system information for ‘%u’: No such file or directory

that error will occur.

So, it was changed stat command path to an absolute path.

What do you think?

timsutton commented 8 years ago

I'm fine with using the absolute paths on principle - though I tend to write a shell script with a specific (minimal) shell in mind. This script's shebang is /bin/sh. Do you have /bin/sh invoking zsh, or otherwise somehow run prepare_iso.sh via zsh normally?

zchee commented 8 years ago

@timsutton Oh, I missed. /bin/sh shebang was enabled.

set -x in script, and result,

...snip...

stat: cannot read file system information for ‘%u’: No such file or directory
+ VEEWEE_UID='  File: "/Users/zchee/src/github.com"
    ID: 100000400000011 Namelen: *       Type: hfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 121837600  Free: 36911599   Available: 36847599
Inodes: Total: 121837598  Free: 36847599'
+ cleanup
+ hdiutil detach -quiet -force ''
+ echo
+ hdiutil detach -quiet -force ''
+ echo
+ rm -rf '' '' '' ''

This problem caused by stat command flag difference of OS X default and GNU coreutils. Not zsh. Sorry.

timsutton commented 8 years ago

Thanks for clarifying - still a good idea to use absolute paths for UNIX utils that differ from GNU versions. Merging!