Same bash script has different behavior in 2 separate scripts. Thoughts?
by uncorrupt3d from LinuxQuestions.org on (#50VPB)
Hey guys,
So I've been working on a really large project for work and I can't seem to crack this bug right now... So I'm trying to get my script to verify all users' home directories exist, using the following code:
Code:#!/bin/bash
grep -E -v '^(halt|sync|shutdown)' /etc/passwd | awk -F: '($7 != "'"$which nologin)"'" && $7 != "/bin/false") { print $1 " " $6 }' | while read -r user dir;
do if [ ! -d "$dir" ];
then echo "The home directory ($dir) of user $user does not exist.";
fi;
done;When I run this as an individual shell script, I get several outputs that look somewhat like:
Code:The home directory (HOME_DIR_PATH) of user USERNAME does not exist.However, when I remove the #!/bin/bash line and copy the rest of the text into a function inside my shell script (same exact thing), I get the following behavior on an infinite loop:
Code:The home directory () of user does not exist.Do you guys have any ideas? I've tried running a separate script with this chunk of bash code from my project to resolve this, rewriting the logic entirely and using shell code checkers- I originally had a syntax issue with awk.
Your help matters a ton! Thx :)


So I've been working on a really large project for work and I can't seem to crack this bug right now... So I'm trying to get my script to verify all users' home directories exist, using the following code:
Code:#!/bin/bash
grep -E -v '^(halt|sync|shutdown)' /etc/passwd | awk -F: '($7 != "'"$which nologin)"'" && $7 != "/bin/false") { print $1 " " $6 }' | while read -r user dir;
do if [ ! -d "$dir" ];
then echo "The home directory ($dir) of user $user does not exist.";
fi;
done;When I run this as an individual shell script, I get several outputs that look somewhat like:
Code:The home directory (HOME_DIR_PATH) of user USERNAME does not exist.However, when I remove the #!/bin/bash line and copy the rest of the text into a function inside my shell script (same exact thing), I get the following behavior on an infinite loop:
Code:The home directory () of user does not exist.Do you guys have any ideas? I've tried running a separate script with this chunk of bash code from my project to resolve this, rewriting the logic entirely and using shell code checkers- I originally had a syntax issue with awk.
Your help matters a ton! Thx :)