this is my code inside a function
function safeChmod_ProcessOctalModes() {
local i=0
local targetpermission=""
local chmod_param=$1
# local folder_chmod_param=`echo $chmod_param | fold -w1`
# echo xxxxxxxxxxxx=$folder_chmod_param >/dev/tty
echo -n "$chmod_param" | \
while read -n 1 ch;
do
if [ $i -eq 0 ]
then
i=$(( i+1 ))
continue
fi
i=$(( i+1 ))
if [ $ch -eq 0 ]
then
targetpermission=($targetpermission"---")
echo tp=$targetpermission >/dev/tty
elif [ $ch -eq 1 ]
then
targetpermission=($targetpermission"--x")
echo tp=$targetpermission >/dev/tty
elif [ $ch -eq 2 ]
then
targetpermission=($targetpermission"-w-")
echo tp=$targetpermission >/dev/tty
elif [ $ch -eq 3 ]
then
targetpermission=($targetpermission"-wx")
echo tp=$targetpermission >/dev/tty
elif [ $ch -eq 4 ]
then
targetpermission=($targetpermission"r--")
echo tp=$targetpermission >/dev/tty
elif [ $ch -eq 5 ]
then
targetpermission=($targetpermission"r-x")
echo tp=$targetpermission >/dev/tty
elif [ $ch -eq 6 ]
then
targetpermission=($targetpermission"rw-")
echo tp=$targetpermission >/dev/tty
elif [ $ch -eq 7 ]
then
targetpermission=($targetpermission"rwx")
echo tp=$targetpermission >/dev/tty
fi
done
echo tp_in_func=$targetpermission >/dev/tty
echo $targetpermission
return 0;
}
Till I am within the while loop, targetpermission
variable is populated correctly. But, as soon as the loop is done, the targetpermission
is none.
This is the output.
chmod_param=0700
tp=rwx
tp=rwx---
tp=rwx------
tp_in_func=
Why is this happening ? How to I retain thetargetpermission
variable's assigned value outside the while loop ?