I have written a shell script that displays username, terminal name, login time etc using case
. The code is:
echo "Press 1 for user name, 2 for terminal name, 3 for login date and 4 for time"
read ch
case $ch in
1)
echo `who | cut -c1-8 | cut -d" " -f1`
;;
2)
echo `who | cut -c9-16 | column`
;;
3)
echo `who | cut -c22-32 | sort`
;;
4)
echo `who | cut -c34-39`
;;
esac
When I run this script the output comes in a single line and I want it to be displayed in a columnar format (i.e. listed across multiple lines in a single column). I have tried the cut
, column
and sort
commands, and yet no respite. The output is:
Press 1 for user name, 2 for terminal name, 3 for login date and 4 for time
1
bioinfo class class class class class class class class class class
[class@bio ~]$
class
and why is it repeated so many times? How did you run the script? Which option did you choose to get this output? Why are you usingecho
for commands that print their output to stdout anyway? – terdon Oct 03 '16 at 08:33