Typing in Unix command lines, Thank you! My unix home directory : /home/myhome Y
ID: 3763865 • Letter: T
Question
Typing in Unix command lines, Thank you!
My unix home directory : /home/myhome
Your unix home directory: /home/yourhome
-------------------------------------------------------------------------------------------------------------
Details
Modifications to your startup files
Make the following modifications in your .bash_profile file in your home directory.
30 points
1.Go to your home directory and edit .bash_profile to define the global variable glenn whose value is the absolute pathname of my home directory.
2. Again in .bash_profile define an alias gh which will take you to my home directory using the variable defined above.
3. Also in .bash_profile define a function go_show, that will
-Go to a specific directory
-Print your current location
-Print the contents of your current directory
-------------------------------------------------------------------------------------------------
The directory this function takes you to will be specified as an argument to the function on the command line. You will need to use a positional parameter to do this.
Details
Go to the hw9 directory and run Unix commands that will execute the steps below.
When you have a command line that does what the step asks you to do, paste it into hw9.sh using nano or any other text editor.
When you have completed all the steps, create an echo statement before the commands for each step, that will print the step number to the terminal.
Test this script by making it executable and run it without using bash.
Only Steps from 4 to 10 should be in your hw9.sh script.
-------------------------------------------------------------------------------------------------------
4.Print to the terminal the value of the variable glenn.
5.Using a pipeline, grep and a command that will show all your global variables, print to the screen the full definition of the variable glenn. Do not use echo to do this. The command to show all global variables was mentioned in the first class were global variables were discussed.
6.Aliases and functions are not global, so they cannot normally be run inside a shell script.
-Go to your home directory (/myhome)
-Run a command that will run the startup file where you defined the alias gh and the function go_show inside your current shell.
-Run a command that will show me all the aliases currently defined.
7.Use the function go_show to move to my home directory (/home/ghoffman) using the global variable glenn.
8.Run a command that will show all the aliases you have currently defined.
9.Run a command that will show the last 20 commands in your history list.
10.Use echo, to print to the terminal a single string enclosed in quotes, and the variable glenn. The string should print the following message:
Explanation / Answer
#go to the home directory
cd ~
#edit .bash_profile
vi .bash_profile
#define global variable glenn
glenn="/home/yourhome"
#define alias gh
gh=glenn
#define the function
go_show(){
#go to the specific directory passed as the function parameter
cd $1
#print the current location
pwd
#print the contents of current directory
ls
}
#invoke the function go_show
go_show
#print the value of variable glenn
echo $glenn
#display all global variable and redirect the output to grep using a pipeline to print the full definition of the variable glenn
grep -n "glenn" | printenv
#go to the home directory
cd ~
#run the startup file
./.bash_profile
#display the alises defined
echo $gh
#Call the function go_show to move the home directory
go_show /home/ghoffman
#display the alises defined
echo $gh
#list the last 20 commands
fc -l -20
#print to the terminal a single string enclosed in quotes and the variable glenn
echo "The home directory of my instructor is $glenn"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.