Question

Write a Bash shell script highestTest.sh that will determine the highest value given to the script....

Write a Bash shell script highestTest.sh that will determine the highest value given to the script. It should take in as a command-line argument a series of numbers. This list could be of any length. Your script should start by finding the lowest value in the list of values. Then it should find how many times that value appears in total in the list. It should then output those results. In addition, I want you to detect if any fractional values have been entered and output an error message.

Homework Answers

Answer #1
highestTest.sh


#!/bin/bash
# checking if arguments passed or not
if [ $# -eq 0 ]
then
  printf "no arguments given \n"
  printf "usage: $0 <num1> <num2> ...."
fi

low=9999999
# regex for detecting integer
re='^[0-9]+$'
# looping through number 
for n in "$@"
do
  # checking if number is complete or not
  if ! [[ $n =~ $re ]] ; then
    # if number is fractional or other printing error message and
    # continue for next number
     printf "Error: $n not an integer skipping this value\n"
     continue
  fi
# checking the lowest number
 if [ "$n" -lt $low ]
     then
        low=$n
  fi
done
count=0
# finding the count of lowest number
for i in "$@"
do
  if ! [[ $i =~ $re ]] ; then
     continue
  fi
  if [[ $i -eq $low ]]
  then
    count=$((count+1))
  fi
  done
printf "lowest number is $low\n"
printf "no of times occured: $count\n"

# OUT

please do let me know if u have any concern....

Know the answer?
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
Similar Questions
In UNIX .Write a bash script that takes a list of usernames as its command line...
In UNIX .Write a bash script that takes a list of usernames as its command line arguments and displays on the screen, for each user name, a message of the form Number of times that logged into this machine is where is to be replaced by the number of recors that the last command output that match exactly. For example, if i enter command logincount mark it should output something like number of times that sweiss logged into this machin...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of userids on the command line 2. For each userid, display the userid, PID, CPU time, and current command for each process owned by that userid Your output should look similar to this example: practice-script-a doug.jones User: doug.jones PID: 8748 TIME: 00:00:00 COMMAND: /usr/lib/systemd/systemd --user User: doug.jones PID: 8749 TIME: 00:00:00 COMMAND: (sd-pam)    User: doug.jones PID: 8750 TIME: 00:00:00 COMMAND: sshd: doug.jones@pts/5 User: doug.jones...
PLEASE WRITE A BASH SCRIPT FOR USE IN JUYPTER NOTEBOOK. Initialize a variable INPUT_FILE that stores...
PLEASE WRITE A BASH SCRIPT FOR USE IN JUYPTER NOTEBOOK. Initialize a variable INPUT_FILE that stores the name of the file 'testdata.csv'. Write an if-else statement in a shell that checks if the input file exists. If the file exists, then display a message "testdata.csv exists," otherwise display a message "testdata.csv does not exist." Initialize an array variable named 'ARR_WORDS' as below: ARR_WORDS=("naresh" "sam" " david" ) Initialize an array variable named 'ARR_COUNTS' of size equal to the length of...
The first script you need to write is login.sh, a simple script that you might run...
The first script you need to write is login.sh, a simple script that you might run when you first log in to a machine. We'll expand this script later, but for now it should include your name, username, hostname, current directory, and the current time. Here is some sample output to help guide you. Note that the bolded lines that start with "[user@localhost ~]$" are the terminal prompts where you type in a command, not part of the script. Of...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set it equal to the empty string (NAME=””). Create a variable called NAME_LENGTH and set it equal to the length of your last name. Output the value of the NAME variable to show that it is empty. 2. Write a FOR loop that executes as many times as there are letters in your name (use the NAME_LENGTH variable in your condition). Use a CASE statement...
Using a Linux terminal, write a script, called UnixHistory.sh, which will generate an abbreviated "tree" of...
Using a Linux terminal, write a script, called UnixHistory.sh, which will generate an abbreviated "tree" of the Unix and Unix like operating system ancestry. The data source, as always, can be found on Wikipedia: https://en.wikipedia.org/wiki/File:Unix_history.svg The Unix history begins with a directory named ResearchUnix that has two children: BSD and Commercial. BSD has two children FreeBSD and NextStep, NextStep has a single child directory: MacOSX. Commercial has one sub-directory named Solaris NOTE all the elements mentioned above are directories, created...
write a script named print_lines.sh that uses head and tail together to print out a specific...
write a script named print_lines.sh that uses head and tail together to print out a specific set of lines from a file. The script should take three arguments: the line number to start at, the line number to stop at, and the file to use. Here's an example run: [user@localhost ~]$ print_lines.sh 7 10 /etc/passwd shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin [user@localhost ~]$ In this example, the script prints line 7 through 10 (inclusive) of the /etc/passwd file. Your script must do...
I did already posted this question before, I did get the answer but i am not...
I did already posted this question before, I did get the answer but i am not satisfied with the answer i did the code as a solution not the description as my solution, so i am reposting this question again. Please send me the code as my solution not the description In this project, build a simple Unix shell. The shell is the heart of the command-line interface, and thus is central to the Unix/C programming environment. Mastering use of...
Write a program in python 3 that uses a custom function to generate a specified number...
Write a program in python 3 that uses a custom function to generate a specified number of random integers in a specified range. This custom function should take three arguments; the number of integers to generate, the lower limit for the range, and the upper limit for the range. Values for these arguments should be entered by the user in main. The custom function should display the random integers on one line separated by single spaces. The function should also...
The Problem Write a C or C++ program which performs specific operations on bits. The user...
The Problem Write a C or C++ program which performs specific operations on bits. The user will specify a value The user can then set, test, or toggle individual bits in the initial value. Input Your program will prompt the user for: An inital value in hexadecimal. This value may be up to 32 bits (eight hexadecimal digits) long. If the user-supplied value is less than eight characters in length, assume the additional digits are zero and are on the...