Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (20 points) Write a profile file (for a bash shell) so that it sets the follo

ID: 3607468 • Letter: 1

Question

1. (20 points) Write a profile file (for a bash shell) so that it sets the following environment: Adds the aliases md for mkdir and rd for rmdir Adds an alias where a user can logout by simply typing x and pressing return Changes the prompt so that it displays the current command number, the current user name, the current shell, and the current directory Gets the full name of the user from the /etc/passwd file and stores it in a variable called full Displays a message "Welcome . "followed by the full name of the user . Displays the message "It is now N followed by the current date and time Displays the line "Last 3 commands" followed by the last three (3) commands executed by the user. Appends the current directory (.) to the PATH variable. .Changes the second prompt (PS2) so that it displays "continue> "whenever additional text is expected from the user. Exports the full variable to any new shell started by the user

Explanation / Answer

Solution to given problem is provided below with explanation and sample output.

alias md="mkdir"
alias rd="rmdir"

alias x="logout"

Changes the prompt so that it displays the current command number, the current user name, the current shell and the current directory.

PS1='#:u:s:w$ '

full=$(getent passwd `whoami` | cut -d ':' -f 5 | cut -d ',' -f 1)

echo "Welcome $full."

echo "It is now $(date)."

echo "Last 3 commands"
echo "$(tail -3 $HISTFILE)"

export PATH=$PATH:.

PS2='continue> '

export full

File: .bash_profile
alias md="mkdir"
alias rd="rmdir"

alias x="logout"

PS1='#:u:s:w$ '

full=$(getent passwd `whoami` | cut -d ':' -f 5 | cut -d ',' -f 1)

echo "Welcome $full."

echo "It is now $(date)."

echo "Last 3 commands"
echo "$(tail -3 $HISTFILE)"

export PATH=$PATH:.

PS2='continue> '

export full

Sample output:

$ ssh 127.0.0.1
someuser@127.0.0.1's password:
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-98-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

197 packages can be updated.
0 updates are security updates.

Last login: Thu Nov 2 06:57:32 2017 from 127.0.0.1
Welcome Some User.
It is now Thu Nov 2 06:58:15 IST 2017.
Last 3 commands
md newfolder
rd newfolder
x
1:someuser:-bash:~$ md newfolder
2:someuser:-bash:~$ rd newfolder
3:someuser:-bash:~$ cat "test
continue> file"
cat: 'test '$' ''file': No such file or directory
4:someuser:-bash:~$ bash
$ echo $full
Some User
$ exit
exit
$ x
Connection to 127.0.0.1 closed.