I made this code

while [ -z "$USER" ]; do
    >&2 echo -n 'Your desired User : '
    read USER

But this doesn't work because $USER is taken from the current user running the script, which isn't what I want.

How can I avoid this in the future for the $USER variable and also other variables where this could happen? Like $PATCH or similar


Use lower-case variable names, or know exactly what upper-case variable names to avoid using.

For non-environment variables (i.e. shell variables), just use lower-case:

while [ -z "$user" ]; do
    read -p 'User name: ' user
  • lol so dumb, I don't know why I didn't thought about that...I guess it doesn't worth the effort to use uppercase variables in this case right? – Freedo Oct 21 '17 at 8:53
  • @Freedo Not really, unless you explicitly want to change system environment variables like PATH etc. – Kusalananda Oct 21 '17 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.