Question

In: Computer Science

Write bash shell scripts for the following problems and submit your answers a single. A )...

Write bash shell scripts for the following problems and submit your answers a single.

A ) Write a linux bash shell script that reads your first and lastname as arguments and print them as shown below. In my example, I name the script as printname.sh. In the example, the two arguments follow the shell scriptname. Submit the script and output print screen.

# sh ./printname.sh Abdullah Konak 
My first name is Abdullah
My surname is Konak

B ) Write a linux bash script that will return the largest of the two numbers that are entered as the argument of the script as shown in the example given below. Return your script and a printscreen from your computer.

# sh ./larger.sh 7 5 
7 is larger of 5 and 7.

C) Extend the script in part B to any number of numbers entered as arguments as the example given below.

# sh ./largest.sh 7 5 3 8 9 10
10 is the largest of numbers entered. 

Solutions

Expert Solution

BASH SHELL SCRIPT FOR A: (printname.sh)

#!/bin/bash


### Command arguments can be accessed as

echo "My first name is" $1
echo "My surname is" $2

SCREENSHOT FOR OUTPUT:

BASH SHELL SCRIPT FOR B:(larger.sh)

#!/bin/bash


# comparing two numbers
if [ $1 -gt $2 ]
then

    # printing $1 as largest number
    echo "$1 is larger of $1 and $2"
else

    # printing $2 as largest number
    echo "$2 is larger of $1 and $2"

fi


SCREENSHOT FOR OUTPUT:

BASH SHELL SCRIPT FOR C:(largest.sh)

#!/bin/bash

# getting the array of comman line arguments
args=("$@")

# variable for counter
i=0

# variable to store the maximum number
max=0

# looping to find the largest number in the array of command line arguments
while [ $i -lt $# ]
do

# setting the first number as the largest number
if [ $i -eq 0 ] #set first number as max
then
      max=${args[i]}

else
      # comparing other numbers in the array, updating the max variable
      if [ ${args[i]} -gt $max ]
      then
        max=${args[i]}
      fi
fi

#increment the counter i by 1
i=$((i + 1))
done

echo "$max is the largest of numbers entered."


SCREENSHOT FOR OUTPUT:


Related Solutions

Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
Please write shell scripts in Kali Linux to complete the following tasks. Task A - Take...
Please write shell scripts in Kali Linux to complete the following tasks. Task A - Take your UIN Write a script like below that reads and displays the MIDAS ID if the following requirements are satisfied: Only lower case letter [a-z] and numeric character[0-9] are allowed MIDAS ID must between 4 to 8 digits Test your script with the following examples: Your MIDAS ID in lower case Your MIDAS ID w.one upper case A string less than 4 digits A...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
Write a bash shell script that takes exactly one argument, a file name. If the number...
Write a bash shell script that takes exactly one argument, a file name. If the number of arguments is more or less than one, print a usage message. If the argument is not a file name, print another message. For the given file, print on the screen its content.
Can you write the shell scripts for these C files (code in C): #include <stdio.h> #include...
Can you write the shell scripts for these C files (code in C): #include <stdio.h> #include <string.h> #include <ctype.h> int main(int argb, char *argv[]){ char ch; int upper=1; if(argb>1){ if(strcmp(argv[1],"-s")==0){ upper=1; } else if(strcmp(argv[1],"-w")==0){ upper=0; } } while((ch=(char)getchar())!=EOF){ if(upper){ printf("%c",toupper(ch)); } else{ printf("%c",tolower(ch)); } } return 0; } ======================================================== #include <stdio.h> #include <stdlib.h> int calcRange(int array[],int size){ int max=array[1]; int min=array[0]; int a=0; for(a=1;a<size;a++){ if(array[a]>max){ max=array[a]; } } for(a=1;a<size;a++){ if(array[a]<min){ min=array[a]; } } printf("%d-%d=%d\n",max,min,max-min); } int main(int arga, char **argv){...
Write a shell program named HELLO2(this should be done in linux, using bash) Consider files in...
Write a shell program named HELLO2(this should be done in linux, using bash) Consider files in the current directory whose names end in 't' or 'z'. For such files only, your program should list certain LINES of the file(s). These lines are those that have at least 4 x's somewhere in the line. Note that the x's may be upper- or lower-case, and may be separated by other characters; so the following 3 lines DO match: XXxX and more things...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within your script  Provide user feedback  Use loops  Use conditionals Remember to use chmod +x to make your file executable! Each script is 5 points in the Specifications portion of the rubric. Don’t forget to maintain good standards and comments. Script 1 – Echo-back some information Write a script name hello.sh that will take the user’s first name as a command line...
write a bash shell program named L1 as follows . L1 expects exactly 2 command line...
write a bash shell program named L1 as follows . L1 expects exactly 2 command line arguments. expects $1 to contain only digits. expects $2 to have exactly 4 characters (can be any character). if NOT exactly 2 command line arguments, echo "need 2 args " and exit. otherwise, if $1 and/or $2 have incorrect value(s) (as above), echo "bad argX", where X is the first incorrect argument, and exit. otherwise, echo "good ". you can use echo,grep, pipe to...
Create an Excel spreadsheet to organize your answers to the following problem, and submit your Excel...
Create an Excel spreadsheet to organize your answers to the following problem, and submit your Excel file as an attachment by clicking on the appropriate button on this page. A firm that is in the 35% tax bracket forecasts that it can retain $4 million of new earnings plans to raise new capital in the following proportions: 60% from 30-year bonds with a flotation cost of 4% of face value. Their current bonds are selling at a price of 91...
create an Excel spreadsheet to organize your answers to the following problem, and submit your Excel...
create an Excel spreadsheet to organize your answers to the following problem, and submit your Excel file as an attachment by clicking on the appropriate button on this page. A company is evaluating the purchase of a machine to improve product quality and output levels. The new machine would cost $1.6 million and would be depreciated for tax purposes using the straight-line method over an estimated six-year life to its expected salvage value of $100,000. The new machine would require...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT