A) join the first and second lines.
B) A variable in single quotes isn't expanded. Use single quotes around the part before the variable and the part after.
C) Since ls | sed will output to stdout, you don't need to use echo
for user in $excl_users; do
if [ "`ls /home|grep $user`" ];then
ls /home | sed '/'$user'/ d'
It would also be better to include more in the pattern in the sed command. Imagine that you have one user named smith and another named smithy. ./progname smith would delete both.
If you look at the pattern of the output of ls, it would be like
If $user has the value of "smith", then this will expand to:
The "$" after smith matches the end of line. The "^" matches the beginning.