0

Can somone help me with this: so i have this script

#!/bin/bash


echo -n "Enter a value for X:(999 to exit): "
read x

until [[ $x == 999 ]]
do

echo -n "Enter a value for Y: "
read y
echo "X="$x
echo "Y="$y
((a=y+x))
echo "X+Y="$a
((s=y-x))
echo "X-Y="$s
((m=y*x))
echo "X*Y="$m
((d=y/x))
echo "X/Y="$d
((m=y%x))
echo "X%Y="$m

echo -n "Enter a value for X:(999 to exit): "
read x
if [[ $x == 999 ]];
then
    exit 0
fi

done
exit 0

but i didnt know how to write the rest of it, the missing thing is: Use the two command line arguments when the script starts if the user supplied them, and then prompt for more numbers to continue in the loop.

0

1 Answer 1

1

Am guessing the arguments you are looking from the user are x and y values. The easiest way to check if user provided arguments is to use $# which gets you the number of arguments given by the user.

So use it like this:

if [ "$#" -eq 2 ];       #2 arguments provided by user
then
    x=$1
    ... 
fi
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.