It's not bash
, but zsh
is available in OS X, so you might try the following (I'm using % for the prompt to indicate when you are in zsh
; for>
is a secondary prompt)
$ zsh
% for x in source/**/*; do
for> chmod $(stat -f "%p" $x) ${x/^source/dest}
for> done
% exit
$
The for loop iterates over all files under source
, recursively. stat -f "%p" $x
outputs the permissions for a file in the source directory, to use as the argument for the command that changes the permissions of the corresponding file (i.e., replace "source" with "dest" in its name) in the destination directory.
(Actually, that loop would work in bash
4 as well, but as you may have noticed, OS X still ships with bash
3.2.)
As a standalone script named foo.zsh
:
#!/bin/zsh
for x in source/**/*; do
chmod $(stat -f "%p" $x) ${x/^source/dest}
done
$ chmod +x foo.zsh
$ ./foo.zsh
or simply
$ zsh foo.zsh