Mastering Linux
< Previous Solution - Home - Next Solution >
/etc/os-release
file and prints it to the screenstudent@vm01:~$ vim distribution.sh
#!/bin/bash
distribution=`grep ^NAME /etc/os-release | cut -d= -f2`
echo "The current distribution is: $distribution"
student@vm01:~$ chmod a+x distribution.sh
student@vm01:~$ ./distribution.sh
The current distribution is: "Ubuntu"
/etc/passwd
and prints the ones with shell ending in shstudent@vm01:~$ vim users.sh
#!/bin/bash
users=`grep sh$ /etc/passwd | cut -d: -f1`
echo "Users with login shell:"
echo $users
student@vm01:~$ chmod a+x users.sh
student@vm01:~$ ./users.sh
Users with login shell:
root student omsagent nxautomation anna mary peter rick"
student@vm01:~$ vim sum.sh
#!/bin/bash
echo "Enter two numbers: "
read N1 N2
sum=$(( N1 + N2 ))
echo "The sum of $N1 and $N2 is $sum"
student@vm01:~$ chmod a+x sum.sh
student@vm01:~$ ./sum.sh
Enter two numbers:
2 3
The sum of 2 and 3 is 5