3

If I was using linux or cygwin I could use stat --format=%a as described here.

But instead I want to use only the tools available in msysgit by default. My main options seems to be parsing the output of ls, but that is not very palatable:

drwxr-xr-x    0 jaxelson Administ        0 Jul 13  2009 PrintHood/
dr-xr-xr-x    0 jaxelson Administ     8192 Jan  3 09:22 Recent/

Are there any easier ways?

Back History: I need to do this because of a bug in sed where it doesn't preserve permissions correctly. For more info see this.

Also the script that is running sed is running as a git-hook.

Community
  • 1
  • 1
Jason Axelson
  • 4,485
  • 4
  • 48
  • 56
  • Hold on, how is this git-related at all? – fge Jan 03 '12 at 20:37
  • @fge I guess it's not directly related. But it is running in the msysgit (git bash) environment as a git hook. I've clarified the answer a little bit and removed the git tag. – Jason Axelson Jan 03 '12 at 20:41
  • It might help to explain what tools you have available. Is there no stat command at all, or does it not support --format? – jordanm Jan 03 '12 at 20:46
  • @jordanm there's no stat command at all. The main tools available are awk, sed and bash. Basically whatever is provided in the default Git Bash environment. – Jason Axelson Jan 03 '12 at 23:12

1 Answers1

2

You could use

perl -e'printf "%o\n",(stat shift)[2] & 07777' <filename>
sschuberth
  • 28,386
  • 6
  • 101
  • 146