'Bash loop trough all users to delete password hints

I have newly started with bash and now I am facing the following problem:

lukas@Lukass-MacBook-Pro Desktop % ./script.sh
delete: Invalid Path
<dscl_cmd> DS Error: -14009 (eDSUnknownNodeName)

I want to remove all password hints from the users. Can anyone help me here?

#!/bin/sh

for user in "$(ls /Users/)"; 
do /usr/bin/dscl . -delete /Users/$user hint
done


Solution 1:[1]

There were a couple of issues in your bash script as per shellcheck.

Line 3: for user in "$(ls /Users/)";
^-- SC2066 (error): Since you double quoted this, it will not word split, and the loop will only run once.

Line 4: do /usr/bin/dscl . -delete /Users/$user hint
^-- SC2086 (info): Double quote to prevent globbing and word splitting.

This should do it:

#!/bin/sh

for userhomedir in /Users/*/
do /usr/bin/dscl . -delete "$userhomedir" hint
done

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexandre Juma