I'm writing a script to configure new debian installs while finding the best solution to confirming that a user exists in the script, the best way I found gives me wierd output.
PROBLEM:
id -u $var
and id -u $varsome
give the same output even though
var
has a value (the username) and varsome
has no value
[19:49:24][username] ~ ~↓↓$↓↓ var=`whoami`
[19:53:38][username] ~ ~↓↓$↓↓ id -u $var
1000
[19:53:42][username] ~ ~↓↓$↓↓ echo $?
0
[19:53:49][username] ~ ~↓↓$↓↓ id -u $varsome
1000
[19:09:56][username] ~ ~↓↓$↓↓ echo $?
0
[20:10:18][username] ~ ~↓↓$↓↓ bash --version
GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
Licens GPLv3+: GNU GPL version 3 eller senere <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[20:27:08][username] ~ ~↓↓$↓↓ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
I got the command from this question on stackoverflow: Check Whether a User Exists
QUESTIONS:
- What is happening here?
- Is there a better way you can find to verify a user exist's in a script?
- Pointers on the script well appreciated
varsome
is empty soid -u $varsome
is the same asid -u
– steeldriver Aug 14 '18 at 20:46id
was there in the first part. If you have some particular part of the script you're struggling with, do ask. But it maybe better placed in a separate question. – ilkkachu Aug 14 '18 at 21:24