Question: Copy the script below and paste into VM . sh text file. ( There may be troubleshooting ) Login as User, Go to the Linux
Copy the script below and paste into VM sh text file. There may be troubleshooting
Login as User,
Go to the Linux Documents directory.
Either create a linuxlab.sh text file either in vim or nano
NOTE:nano linuxlab.sh
This will open the nano text editor where you can paste your script. Here's an example script:
#binbash
# This is an example script
echo "Hello, World!"
Save and exit the editor CtrlO to save, CtrlX to exit in nano
Run and study the output the sh script from the command line.
Make the Script Executable
After creating the script, you need to make it executable. You can do this using the chmod command:
chmod x linuxlab.sh
This command gives execute permission to the script file.
Run the Script
Once the script is executable, you can run it using the following command:
linuxlab.sh
The prefix RELATIVE PATH tells the terminal to execute the script from the current directory.
homeUserlinuxlab.sh ABSOLUTE PATH tells the terminal to start from the top of the Linux file system.
You can run the Script with a Specific Interpreter If the script has the #binbash shebang
bash examplescript.sh
Step summary:
Make sure the script has execute permissions chmod x
The script should start with a shebang #binbash to specify the interpreter optional but recommended
If you're running the script in a different directory, use the full path to the script or cd into the directory containing the script first.
Check the resulting output for correctness and paste a copy of it in a new text file.
Copy the resulting output including the original command line and paste it in a new text file. LinuxLabtxt
Upload both the "LinuxLab.txttxt and LinuxLab.sh files
The script includes:
The three execution types:
sequential
recursive iterative looping including a program test loop not only command recursion option
conditional
User interface error handling
Resulting output
SCRIPT
#binbash
# Function to check if a directory exists and delete it
deletedirectory
if d $; then
echo "Directory $ exists. Deleting it
rm rf $
fi
# Prompt for the college directory name
echo n "Please enter the name of the main directory default is 'College' or type 'END' to exit:
read collegeDirName
# If the user enters "END", exit the script
if $collegeDirName" "END" ; then
echo "Exiting script."
exit
fi
# If the user didn't enter
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
