Skip to content
Advertisement

Bash Scripting checking for home directories

I’m trying to create a script to check if user accounts have valid home directories.

This is what i got at the moment:

JavaScript

This works. I get the expected output which is the username of the account with an invalid home directory.

eg. output

JavaScript

However, I am unable to make it so that ONLY if there is no issues with the valid home directories and all of them are valid, echo “All home directories are valid”.

Advertisement

Answer

You could set a flag, and unset it if you see an invalid directory. Or you could simply check whether your loop printed anything.

You have a number of common antipatterns which you’ll want to avoid, too.

JavaScript

A proper tool prints its diagnostic output to standard error, not standard output, so I added >&2 to the end.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement