Yes, this is homework. No, my teacher has not actually taught us scripting, he kind of just expected us to pick it up along the way since this is an accelerated course. I'm not expecting you to just give me the answer (But I'm not complaining if you do), but I am asking for help.
The first problem is "Write a shell script that will add two numbers, which are supplied as command line arguments, and if this two numbers are not given, show an error message."
I can do the first part of that
works just fine to add two numbers supplied as command line arguments, but now I need to figure out how to make it so that if there are no arguments given to return an error message.Code:echo `expr $1 + $2`
I was looking through the book and I was thinking that the ${VAR:-} thing would be useful as in.
I'm more than positive I'm doing something wrong because I simply dont know the syntax and all the examples I'm getting off of online shell scripting crap is the stuff you do in by command line without writing an actual script where you put an $ before every line, well, fuck, honestly I just dont know what I'm doing.Code:$1=${1:- "Not Set"} if $1 = "Not Set" ; then echo "No arguments" else echo `expr $1 + $2` fi
XI Wiki



