Question

Write a bash script that will: Take in three parameters. Display the name of the filename...

Write a bash script that will:

Take in three parameters. Display the name of the filename of your shelf program – such as: ”You executed the shell program $0” Display the three parameters in one line or three different lines with text telling the user what the variable is.

Comment all lines as to what they do.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if you need more information:-

================================================

*) Display the name of the filename of your shelf program – such as: ”You executed the shell program $0”
echo "You executed the shell program $0"

*) Display the three parameters in one line or three different lines with text telling the user what the variable is.

ss139t@ss139t:~/q157$ cat myScript.sh
#!/bin/bash

#Display the name of the filename of your shelf program

echo "You executed the shell program $0" #Displays the script name to the screen along with message

#start of if conditon
if [ "$#" -lt "3" ];then #Check if the parameters passed to this script is less than three(3)
echo "You must provide Three parameters" #Displays the validation message to screen
exit 1 #Returns from script and exit with return code 1
fi #end of if condition

echo "First parameter is $1"
echo "Second parameter is $2"
echo "Third parameter is $3"

echo "========================================"
#The below code is just to determine the entered parameter is number or non-numeric
re='^[0-9]+$' #regex to make sure supplied value contains only the numbers

if ! [[ $1 =~ $re ]];then
echo "First parameter $1 is non-numeric"
else
echo "First parameter $1 is number"
fi

if ! [[ $2 =~ $re ]];then
echo "Second parameter $2 is non-numeric"
else
echo "Second parameter $2 is number"
fi

if ! [[ $3 =~ $re ]];then
echo "Third parameter $3 is non-numeric"
else
echo "Third parameter $3 is number"
fi

ss139t@ss139t:~/q157$
===========

Note: if not required , you can ignore from line number : 19

=============

OUTPUT:-

================


ss139t@ss139t:~/q157$ bash myScript.sh 1 2 xyz
You executed the shell program myScript.sh
First parameter is 1
Second parameter is 2
Third parameter is xyz
========================================
First parameter 1 is number
Second parameter 2 is number
Third parameter xyz is non-numeric
ss139t@ss139t:~/q157$ bash myScript.sh 1 2 3
You executed the shell program myScript.sh
First parameter is 1
Second parameter is 2
Third parameter is 3
========================================
First parameter 1 is number
Second parameter 2 is number
Third parameter 3 is number
ss139t@ss139t:~/q157$

===

Please let me know if you need more information:-

===

Thanks

===

Add a comment
Know the answer?
Add Answer to:
Write a bash script that will: Take in three parameters. Display the name of the filename...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a script using the bash shell to add new users to the system. The script...

    Write a script using the bash shell to add new users to the system. The script should read user information from a comma-delimited file (each field should be separated by a comma). The filename should be passed to the script as a command-line argument. Be sure the script contains a usage clause. The input file should contain the user information with one user per line. As the system administrator, you should determine the information necessary for each user to properly...

  • Programming Exercise 4.9 Write a script named numberlines.py. This script creates a program listing from a...

    Programming Exercise 4.9 Write a script named numberlines.py. This script creates a program listing from a source program. This script should: Prompt the user for the names of two files. The input filename could be the name of the script itself, but be careful to use a different output filename! The script copies the lines of text from the input file to the output file, numbering each line as it goes. The line numbers should be right-justified in 4 columns,...

  • Write a bash shell script called direct.sh. This script will take an arbitrary number of command...

    Write a bash shell script called direct.sh. This script will take an arbitrary number of command line arguments. Your script should create directories starting with the first argument, then the second directory inside the first one, and then the next one inside the second one, and so on.

  • Write a Bash script called hello that uses command line arguments to allow the user to...

    Write a Bash script called hello that uses command line arguments to allow the user to put two strings after the command name, when the script is being executed. These strings should represent a first and last name. The script should then write out a greeting to the user that includes the first and last name. Here is an example of how the script might work (the first line represents what the user types to launch the script): [user@HAL] hello...

  • NIT1202 Operating Systems UNIX Script You are required to write a Bourne Again Shell Script (bash)...

    NIT1202 Operating Systems UNIX Script You are required to write a Bourne Again Shell Script (bash) to manage a menu driven program. When executed the user should be presented with a menu with 4 (four) options: Print the following user information: the home directory, path, userid , login shell together with the current date and time. Ask a user a range and it displays eight random number between the range. [Range difference must be 100. Example Enter a range: 200...

  • Unix classes Write a bash script that take in three integer numbers from the command line...

    Unix classes Write a bash script that take in three integer numbers from the command line and print out the sum and the average. Name the script awesum.sh hb1170uxb4:~$ ./awesum.sh 100 200 300 sum: 600 average: 200 hb1170uxb4: ~S

  • Hello, I am attempting to write a basic shell script using bash. It will need to...

    Hello, I am attempting to write a basic shell script using bash. It will need to print the user, host, time, and date. It will need to take user input for a txt file to be searched and create a new file to save the results. It must print the number of lines and characters in the text. The user will need to enter three words to be searched, and the number of occurrences of those words in the text...

  • How to write a bash shell script that prints a hollow box after user enters number...

    How to write a bash shell script that prints a hollow box after user enters number of lines, ie "bash hbox 4" , prints: **** *   * *   * **** My code doesnt work. i need it to take in the argument from the command line: ./hbox 4 "*" echo "Enter number of rows" read sz clear for (( x = 1; x <= $sz; x++ )); do     for (( y = 1; y <= $sz; y++ )); do...

  • Please write a bash script for the following two questions, thank you.    Write a shell script...

    Please write a bash script for the following two questions, thank you.    Write a shell script “6-1.sh” to calculate the exponentiation using while loop. This script needs to take two inputs like “6-1.sh a b”, and outputs the result of “ab”. Note: You need to implement it, DO NOT use the exponentiation operation provided by the Linux.    Write a shell script “6-2.sh” to calculate the factorial of a number using while loop. This script needs to take one input...

  • Write a script using bash that accepts three arguments from the user, then prints out the...

    Write a script using bash that accepts three arguments from the user, then prints out the following: The name of the script The value of each argument

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT