This works for
basic permissions (rwx). I don't know if it will choke on special bits (sticky bit, suid, and sgid). If it does, I trust this is enough of a start for you to figure out how to handle them.
Code:
#!/bin/bash
target_file=test_file
original_perms=$( ls -l ${target_file} | cut -c 2-10 )
chmod_mode="u=$(echo ${original_perms} | cut -c 1-3 | sed 's/-//g'),\
g=$(echo ${original_perms} | cut -c 4-6 | sed 's/-//g'),\
o=${echo ${original_perms} | cut -c 7-9 | sed 's/-//g')"
echo " Original permissions: ${original_perms}"
echo " chmod mode string: ${chmod_mode}"
echo
echo "Changing permissions to: 777"
chmod 777 ${target_file}
echo "---Displaying file listing---"
ls -l ${target_file}
echo "Changing permissions back to original settings"
chmod ${chmod_mode} ${target_file}
echo "---Displaying file listing---"
ls -l ${target_file}
exit 0