Re: 'Inverse' chmod?
> It works fine from the command line,
> but I tried it in a shell script with no luck.
> #! /bin/bash
> perl -e 'printf "%#o", ((stat($1))[2] & 0x1ff)'
> Needless to add I know as much about shell scripts
> as Hillary does about New York.
Yeah, the problem is that the $ is inside a ' (perl script).
Try something like:
perl -e 'printf "%#o", ((stat("'"$1"'"))[2] & 0x1ff)'
How it works:
Unix shells silently concatenate strings when they are adjacent.
So these are equivalent:
foo "abc"
foo "a"'b'"c"
The argument to perl -e above is three strings:
'aaa'"bbb"'ccc'
where aaa == printf "%#o", ((stat(" note trailing doublequote
bbb == $1 argument gets substituted here
ccc == "))[2] & 0x1ff) note leading doublequote
So, if you give "dd" as a filename the perl call gets an argument:
printf "%#o", ((stat("dd"))[2] & 0x1ff)
which is kind of what you want???
--
Charles B. (Ben) Cranston
mailto:zben@ni.umd.edu
http://www.wam.umd.edu/~zben
Reply to: