I want to get the home directory of a user of a unix system. Why doesn't the following work:
# sudo su $offender -c "bash -s < <(echo echo \$HOME)"
sh: Syntax error: redirection unexpected
It works for me in Ubuntu and Fedora using sudo su $offender -c "echo \$HOME"
You could also gouge it from your /etc/passwd file like so:
grep "^$offender" /etc/passwd | cut -d':' -f6
Don't really know why it doesn't work, but here's a way to get the home directory that does not involve spawning a shell as that user:
getent passwd "${offender:?No Offending Account Given}" | awk -F':' 'NR==1{print $6}'
sudo su ${offender} -c 'bash -c "echo $HOME"', or sudo su ${offender} -c "bash -s <<<'echo \$HOME'" if you insist on running a process as the user you want to get information for.
sudo su $offender -c 'echo $HOME'work for you?< <doesn't make much sense. What i'm asking is, why all the shell gymnastics? It'd seem you don't need all the redirection and echoing commands and such...shisn't a link tobash? (On my RH/CentOS Linux boxes,shis actuallybash...probably why i'm not seeing the issue you're having.)