Do not pipe to your while
loop, write it like this:
while read sh
do
...
done < <(cut -d: -f7 /etc/passwd)
If you do cmd | while
then the while is in a different process. It inherits your local variables but it cannot modify them. By using input redirection, the while
stays within the current process.
Btw, the first <
there is for input redirection, and the <(...)
after that is process substitution. You need a space in between otherwise the shell cannot separate these operators. You can read more about process substitution in man bash
in the Process Substitution section.