There are a few errors. First, you’re creating your files with commas
between each set of three:
touch ./{r,-}{w,-}{x,-},{r,-}{w,-}{x,-},{r,-}{w,-}{x,-}
But then you’re removing colons. The colon should be a comma.
syntax="${i//:}"
This might cause trouble if the script is in the same directory:
for i in *
Of course if you’re running it as ../myscript
or such, there’s no
problem. But if the script is in the same directory, this will avoid it:
for i in ???????????
(Assuming you didn’t give it an 11-character name, of course.)
Finally, the big bug. You’re splitting the filename into three strings
such as u='-w-' g='r-x' o='-wx'
. These are the wrong syntax for
chmod
; you need to remove the hyphens first. So, after the split:
u=${u//-}
g=${g//-}
o=${o//-}
With all these changes, we arrive at this, which works:
touch ./{r,-}{w,-}{x,-},{r,-}{w,-}{x,-},{r,-}{w,-}{x,-}
for i in ???????????
do
syntax="${i//,}"
u=${syntax:0:3}
g=${syntax:3:3}
o=${syntax:6:3}
u=${u//-}
g=${g//-}
o=${o//-}
chmod u="$u",g="$g",o="$o" -- "$i"
done