Skip to main content
copied quoting error corrected (see comments)
Source Link
Hauke Laging
  • 94.8k
  • 21
  • 132
  • 185

You need grep -q. If you don't distinguish between more exit codes than "0" and "other" there is no need to seperate grep and if:

if grep -q '^$"^${uzer}:'" /etc/passwd; then
  echo "User does exist :)"
else
  echo "No such user"
fi

You need grep -q. If you don't distinguish between more exit codes than "0" and "other" there is no need to seperate grep and if:

if grep -q '^${uzer}:' /etc/passwd; then
  echo "User does exist :)"
else
  echo "No such user"
fi

You need grep -q. If you don't distinguish between more exit codes than "0" and "other" there is no need to seperate grep and if:

if grep -q "^${uzer}:" /etc/passwd; then
  echo "User does exist :)"
else
  echo "No such user"
fi
Source Link
Hauke Laging
  • 94.8k
  • 21
  • 132
  • 185

You need grep -q. If you don't distinguish between more exit codes than "0" and "other" there is no need to seperate grep and if:

if grep -q '^${uzer}:' /etc/passwd; then
  echo "User does exist :)"
else
  echo "No such user"
fi