bash - How to use chmod to change the permissions of a file, with a variable -
i'm trying change permission of file, , have path of file stored in array.
chmod 744 ${arrayoffiles[1]}
the 1 placeholder, in reality i
within loop. whenever run command error:
chmod: missing operand after ‘744’
and i'm not sure why. have checked ${arrayoffiles[1]}
contains full path , does.
i'm not sure why isn't working.
thanks in advance.
edit:
local i=0 filepermission="-rwxr--r--" directorypermission="-rwxr-xr-x" (( i=0; i<=${#arrayoffilepermissions[@]}; i++)) if [ "${arrayoffilepermissions[$i]}" != "$filepermission" ]; echo "file ${arrayoffiles[$i]} has wrong permission: ${arrayoffilepermissions[$i]}" echo ${arrayoffiles[$i]} chmod 744 ${arrayoffiles[$i]} echo "this has been changed to: $filepermission" fi done
the array arrayoffiles contain file names, , arrayofpermissions contain permissions. trying make permission rwxr--r--
.
the if statement running, it's ever trying value array fails, , draws blank
Comments
Post a Comment