Answered step by step
Verified Expert Solution
Question
1 Approved Answer
BASH Part 1: Exploring BASH variables and return codes 1. Login as root 2. Run the command true (this emulates a successful command 3. Now
BASH Part 1: Exploring BASH variables and return codes 1. Login as root 2. Run the command true (this emulates a successful command 3. Now run the command echo $? the $? is the variable that contains the retur cade of the last execution. What is the value? 4. Now run the command false (this emulates a failed command) 5. Display the variable again what is the value? 6. What are the contents in your PATH variable? Where can you store a script to have it located by BASH? 7. What are the contents of your HOME variable? & Run sudo bash to open a shell within the current shell 9. What the processid of the current shell display the $5 variable? 10, Now run kill-9 (PID from question 8) What happened? stops the process) (please note kill-9 forcefully Creating your first script 1. Create a bin directory in your home directory 2. Open vim /bin/firstScript.sh 3. Include the shell you wish it to run under on the first line #l/bin/bash 4. Then use the echo command to output something to the screen 5. Now write and quit vim 6. Now make the file executable with: chmod uex /bin/firstScript.sh 7. Now run the file using-bin/firstScript.sh for if your path has /bin just firstScript.sh) Using conditional logic 1. Create a second script using vim called-/bin/condScript.sh 2. This script should take in a file name in argument one check if it exists and cat the contents if it does. If no argument is passed the user should receive an error, and if the file doesn't exist the user should also receive an appropriate error. 3. Then we want to check to see if a first argument string was not provided If [[ --- $1]]; then 4. If the first argument has a length of O echo "Valid usage condScript.sh filename> 5. Next we want to check if the file does not exists with, if it doesn't echo the appropriate error: elif [[ ! -- "/root/$1" ]]; then 6. Otherwise echo "You have selected $1, and its contents are." else
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started