0% found this document useful (0 votes)
79 views11 pages

Cs Assignment

The document contains instructions and answers for 12 questions about bash shell commands and scripting. Key points covered include: 1. Finding the bash program location and version. 2. Shell configuration files read at login and why Ctrl-C doesn't exit bash. 3. Scripts to count running processes, display hostname, and show home directory, terminal type, and runlevel services. 4. Creating and using local variables and removing one. 5. Editing profile to greet all users at login and set customized prompts. 6. Script to list users who use bash as default shell. 7. Script to display localhost from hosts file and count matches. 8.

Uploaded by

CharlieElizabeth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views11 pages

Cs Assignment

The document contains instructions and answers for 12 questions about bash shell commands and scripting. Key points covered include: 1. Finding the bash program location and version. 2. Shell configuration files read at login and why Ctrl-C doesn't exit bash. 3. Scripts to count running processes, display hostname, and show home directory, terminal type, and runlevel services. 4. Creating and using local variables and removing one. 5. Editing profile to greet all users at login and set customized prompts. 6. Script to list users who use bash as default shell. 7. Script to display localhost from hosts file and count matches. 8.

Uploaded by

CharlieElizabeth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Bash lab

1. Where is the bash program located on your system?


Ans:
Command: $ find $BASH or echo $BASH

2. Use the --version option to find out which version you are running.
Ans:
Command: bash --version

3. Which shell configuration files are read when you login to your system using the graphical
user interface and then opening a terminal window?
Command: sudo /bin/bash
4. Can you explain why bash does not exit when you type Ctrl+C on the command line?
Ans:
In Section 1.2.2.3.3 the Guide explains that an interactive shell catches and handles SIGINT.
This keeps Ctrl+C from exiting the shell. Using Ctrl+C is a common way of sending the SIGINT
signal to a running shell, script, or program. However, it is not required for whatever
receives the SIGINT to actually exit; it may do something else in response.
5. Write a script to determine how many processes are currently running on your system. Use
ps and wc, the first line of the output of ps is not a process!
Ans:
Create a script name process.sh with command sudo gedit process.sh with following
content:

Navigate to a directory where your process.sh is located and make the file executable:
Sudo chmod +x process.sh
Run the script by type ./process.sh then it will respond as below:
6. Write a script to display the system hostname. Only the name, nothing more!
Ans:
Create a script name hostname.sh with command sudo gedit hostname.sh with following
content:1

Navigate to a directory where your hostname.sh is located and make the file executable:
Sudo chmod +x hostname.sh
Run the script by type ./hostname.sh then it will respond as below:
7. Write a script to display the path to your homedirectory and the terminal type that you are
using. Additionally it shows all the sevices started up in runlevel 3 on your system. (hint: use
HOME, TERM and ls /etc/rc3.d/s*)
Ans:
Create a script name q7.sh with command sudo gedit q7.sh with following content:

Navigate to a directory where your q7.sh is located and make the file executable:
Sudo chmod +x q7.sh
Run the script by type ./q7.sh then it will respond as below:
8. Create 3 variables, VAR1, VAR2 and VAR3; initialize them to hold the values "thirteen", "13"
and "Happy Birthday" respectively.
i) Display the values of all three variables.
ii) Are these local or global variables?
iii) Remove VAR3.
iv) Can you see the two remaining variables in a new terminal window?

Ans:

(i),(iii)

(ii) If variables are exported, there are global variables. However, if these variables are not
export, there are local.

(iv) No, two remaining variables cannot be seen in new terminal window except new shell.
9. Edit /etc/profile so that all users are greeted upon login (test this).
i) For the root account, set the prompt to something like "Danger!! Root is doing stuff in \w",
preferably in a bright color such as red or pink or in reverse video mode.
ii) Make sure that newly created users also get a nice personalized prompt which informs
them on which system in which directory they are working. Test your changes by adding a
new user and logging in as that user.
Ans:
(i)

Press Ctrl+Alt+F1, then login to administration user.

Use command sudo nano .bashrc to edit the file .bashrc

Add “setterm –reverse” and “echo DANGER THE ROOT IS WORKING $(pwd) at last line.

Command “reset” to restart and login again.


(ii)

Command “exit” and login with other user.


10. Write a script that will display a list of all the users on your system who log in with the Bash
shell as a default.
Ans:
Create a script name q10.sh with command sudo gedit q10.sh with following content:

Navigate to a directory where your q10.sh is located and make the file executable:
Sudo chmod +x q10.sh
Run the script by type ./q10.sh then it will respond as below:
11. Write a script that will display localhost information from the /etc/hosts file, display the line
number(s) matching the search string and count the number of occurrences of the string.

Ans:

Create a script name q11.sh with command sudo gedit q11.sh with following content:

Navigate to a directory where your q11.sh is located and make the file executable:
Sudo chmod +x q11.sh
Run the script by type ./q11.sh then it will respond as below:
12. Write a script that will make a list of files in your home directory that were
changed less that 10 hours ago, using grep, but leave out directories. The
script should generate comprehensible output.

Ans:

Create a script name q12.sh with command sudo gedit q12.sh with following content:

Navigate to a directory where your q12.sh is located and make the file executable:
Sudo chmod +x q12.sh
Run the script by type ./q12.sh then it will respond as below:

You might also like