I am learning basic unix shell scripting now. I was trying a code from here to write my username but it is not working.
The code is:
#
# Script to print user information who is currently logged in , current date & time
#
clear
echo "Hello $USER"
echo "Today is \c ";date
echo "Number of user login : \c" ; who | wc -l
echo "Calendar"
cal
exit 0
I tried $whoami
instead of $user
, but still it is not showing my username. What can be the issue here? I am using vim editor in Ubuntu.
$USER
is not working try, $LOGNAME
. If you have already learned about command substitution then you can use $(whoami)
or $(id -n -u)
. Ref\c
in echo
wont work unless you specify with -e
(stands for enable interpretation of backslash escapes).
echo -e "Today is \c ";date
It seems you want to prevent the trailing new line character introduced by echo
. Another way to achieve this is to just add -n
. Then you don't need -e
and \c
.
echo -n "Today is "; date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With