Hi:
echo "Escriba el nombre de usuario: \c"
read user
lsuser -a $user 2>/dev/null || (echo "Usuario no valido en el sistema. Abortando." && exit 1)
I want:
- If 'lsuser -a $user' fails, script exits but hide stderr.
- If 'lsuser -a $user' succeeds, script continue, and hide stdout.
thx in advance
Israel.
panyam
2
1>/dev/null at the end of your statement which outputs to the screen.
but if I use 1>/dev/nulll when 'lsuser -a $user' fails I see stderr on screen...I want to hide stderr or stdout on both ways (fails or succeeds)
regards
Israel.
methyl
4
lsuser -a $user 2>/dev/null 1>/dev/null
lsuser -a $user 1>/dev/null 2>/dev/null
Maybe
lsuser -a $user >/dev/null 2>&1 || (echo "Usuario no valido en el sistema. Abortando." && exit 1)
umm.. there is something odd here... I realized the problem is in (echo "Usuario no valido en el sistema. Abortando." && exit 1) string... if I use:
lsuser -a $user >/dev/null 2>&1 || exit 1 it works
do you know why?
I'm using ksh93 on AIX.
thanks again
frans
8
Try without running a subshell: use {} in state of (). You can write &>/dev/null to redirect both stdout and stderr
lsuser -a $user &>/dev/null || { echo "Usuario no valido en el sistema. Abortando." && exit 1 }
sorry the delay...frans
I tried with { } but it doesn't work on my aix..
another example:
grep "$user:" /etc/security/user.roles || (echo "El usuario no tiene roles asignados" && exit 1)
here, exit status is always 1, even if grep if OK or not
What am I missing here? How can I make an echo AND exit if grep fails?
thanks a lot
Try ';' instead of '&&'
grep "$user:" /etc/security/user.roles || (echo "El usuario no tiene roles asignados" ; exit 1)
well... this way works but I dont know really how
grep "$user1:" /etc/security/user.roles 1>/dev/null || echo "El usuario no tiene roles definidos" && (exit 127)
regards