0

How to write a bash shell script that accepts 5 different integer values as command line arguments and displays the smallest, the largest and the middle argument. the script uses: An if statement. The if statement should give an error message if the number of arguments is not exactly 5 and then it executes the exit command to end the script.

A push in the right direction or something would greatly be appreciated. thanks

4
  • Have you started this exercise yourself? With which parts of the script are you struggling? Commented Apr 16, 2011 at 0:50
  • Is this homework - if so please tag it as such. Commented Apr 16, 2011 at 0:50
  • This is almost certainly homework. Commented Apr 16, 2011 at 1:03
  • @jabbie: Why? Commented Apr 16, 2011 at 1:04

1 Answer 1

2

Here's a starter for you, giving you all of the constructs you'll need but without doing the exercise for you...

#!/usr/bin/env bash

if (( ${#@} == 5 )); then
    echo "Correct number of arguments, I'll now play with ${@}, starting with $1 and ending with $5..."
elif (( ${#@} < 5 )); then
    echo $(( 5 - ${#@} )) " more arguments needed."
elif (( ${#@} > 5 )); then
    echo $(( ${#@} - 5 )) " fewer arguments needed."
fi

If you run through the Bash Scripting Tutorial, you should be able to do this in no time at all!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.