开发者

unix bash shell script writing

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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜