In a standard bash shell, I was trying to cat a file from several users' home directories which are on a root-squashed NFS mount so I couldn't just read them as root :
sudo -u userA cat ~userA/blah
.. works fine. However trying this in a loop doesn't work :
for x in userA userB userC; do sudo -u $x cat ~$x/blah; done
.. doesn't work :
cat: ~userA/blah: Permission denied
cat: ~userB/blah: Permission denied
cat: ~userC/blah: Permission denied
Now there's other ways to achieve the desired result but what I'm trying to understand is why the for loop doesn't work
for x in userA userB userC; do sudo -u $x cat /home/$x/blah; done ....is enough to fix it. – Gaspode Aug 23 '16 at 08:27