Question

In: Computer Science

In Linux (Ubuntu), write a script to check command arguments (3 arguments maximum). Display the argument...

In Linux (Ubuntu), write a script to check command arguments (3 arguments maximum). Display the argument one by one. If there is no argument provided, remind users about the mistake. If there is an easy way to use a loop to get all arguments, use it?

a. Display the source code in an editor (#4-1)

b. Execute your script in the terminal, and display the command and the result (#4-2)

Solutions

Expert Solution

Hi,
Thank you for the opportunity to help you with your assignment.

The following is the code for your requirements as in the instructions.I have made sure to include all that is necessary for you to complete this assignment.

Please ensure you run "chmod +x argsprinter.pl" before you run the script.

I have added comments in the code for your reference. The output and screenshot is at the end of this answer.

If you have any queries, need changes in the code or need help in following the code, leave me a comment.

I will reply within reasonable time.

If this answer helps you with your assignment, do upvote it.
Your vote will motivate me to work better.

The following is the code
//File: argprinter.pl


#!/usr/bin/perl
#counter used to display the argument number
my $arg = 1;
#Check if any argument is passed to this script, else exit
if ($#ARGV <= 1 ) {
print "You need to pass arguments to this script.\n";
exit;
}
#Iterate and print each argument
foreach my $a(@ARGV) {
print "Arg # $arg : $a\n";
$arg++;
}

Here is the source in the editor

And finally, this is the output when the code is executed
//Output:


Related Solutions

LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
Ubuntu Linux HW5: text processing; scripting 1. Write a Linux command to rewrite the /var/passwd file...
Ubuntu Linux HW5: text processing; scripting 1. Write a Linux command to rewrite the /var/passwd file to have a tab for each delimiter ':'. Hint: use tr 2. Write a Linux command to extract the user names and sort them. Hint: use cut 3. Write a for loop to to display a time table, e.g., 17 x 1 = 17; 17 x 2 = 34; etc., as follows: 17 x 1 = 17 17 x 2 = 34 17 x...
Write a script named countmatches that expects at least two arguments on the command line. The...
Write a script named countmatches that expects at least two arguments on the command line. The first argument is the pathname of a dna file containing a valid DNA string with no newline characters or white space characters of any kind within it. (It will be terminated with a newline character.) This dna file contains nothing but a sequence of the bases a, c, g, and t in any order. The remaining arguments are strings containing only the bases a,...
UNIX ONLY Write a bash script that will accept a filename as a command line argument....
UNIX ONLY Write a bash script that will accept a filename as a command line argument. Your script should first check whether the filename has been passed as argument or not (hint: at least one argument has to be provided). If no argument has been provided your script should display appropriate message and exit. If a file name has been provided, your script should check if the file exists in the current directory and display the contents of the file....
(Complete Using Ubuntu) Please try each command in Linux system, and get screenshots (you may put...
(Complete Using Ubuntu) Please try each command in Linux system, and get screenshots (you may put multiple commands in one screenshot) which can show how actually each command runs. Also, give a brief description (one or two sentences) for each command. For the commands which have multiple switches/parameters, please try one popular switch/parameter. Linux Commands: rm,cp ,mv (name), ld, ftp, more, less, cat (date), tar, top, ps (name), kill, df, last, patch, mkdir (date)
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs. Take a screenshot showing your shell program and its execution step. Design a shell program to remove all the shell programming files ending with sh on your...
Using Linux in VirtualBox To display your system date: Type date in the command line, and...
Using Linux in VirtualBox To display your system date: Type date in the command line, and press Enter. What do you see?                                            You might see the abbreviation EDT (Eastern Daylight Time) instead of EST (Eastern Standard Time), or another time zone abbreviation, such as MDT (Mountain Daylight Time) or CST (Central Standard Time). Notice also that UNIX/Linux uses a 24-hour clock. Type Date in the command line, and press Enter. What error do you see?                                    The system error...
Introduction Write in C++ at the Linux command line a program that is the same as...
Introduction Write in C++ at the Linux command line a program that is the same as the previous collection app project but now uses a class to store the items and also can save the items to a file that can be read back into the array by the user when the program is re-started. You can use your project 1 submission as a starting point or you can do something new as long as it meets the listed requirements....
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string expressed as -rwxrwxrwx and prints out whether or not theobject is a directory, file or link. The string is read in from standard input. Convert String (Part 2) Modify the script so its able to print out the octal permission which the string represents along with the file type. This is in addition to part 1. Convert String (Part 3) For the script in...
Perl is a programming language that can be used on Linux. Write a Perl shell script...
Perl is a programming language that can be used on Linux. Write a Perl shell script named phone.pl that prompts the user to enter first or last or any portion of person’s name, so that can be found the appropriate entry in the phone directory file called “phones”. If the user tries to enter name as the argument on the command line, he/she will get a warning message “You need to provide name when prompted by this script!” If the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT