Results 1 to 7 of 7
Okay, I am taking a shell scripting course and this is the problem:
"Write a script that displays four variables (var1, var2, var3, and var4) that you enter from the ...
- 11-23-2008 #1Just Joined!
- Join Date
- Nov 2008
- Posts
- 5
Parameter substitution
Okay, I am taking a shell scripting course and this is the problem:
"Write a script that displays four variables (var1, var2, var3, and var4) that you enter from the command line. If var1 isn't set, display "NO VAR1". If var2 isn't set, assign "NOW V2" to it and display the value. If var3 is set, display "VAR3 SET". If var4 isn't set, display "Oh, NO!" and exit. Have an echo line at the very end of the script that echoes "All done". Use parameter substitution."
I'm stuck, any suggestions?
- 11-23-2008 #2
Don't you already have a post on this ?
You know about the rule concerning Homework !?!
Men occasionally stumble over the truth,
but most of them pick themselves up
and hurry off as if nothing had happened.
Winston Churchill
... then the Unix-Gods created "man" ...
- 11-23-2008 #3Just Joined!
- Join Date
- Nov 2008
- Posts
- 5
no, i don't.. there is a rule?
- 11-23-2008 #4Just Joined!
- Join Date
- Nov 2008
- Posts
- 5
i solved it
i solved it, finally
var1=`eval echo "$""$1"`
echo ${var1:-"NO VAR1"}
var2=`eval echo "$""$2"`
echo ${var2:="NOW V2"}
var3=`eval echo "$""$3"`
echo ${var3:+"VAR3 SET"}
var4=`eval echo "$""$4"`
echo ${var4
"Oh NO!"}
echo all done
- 11-23-2008 #5
There is a forum rule about no homework questions.
Some posters ask us to give them entire scripts to complete their homework questions ... so they don't have to learn how to do it and get the credit for completing the homework.
It is good that you figured it out.
Men occasionally stumble over the truth,
but most of them pick themselves up
and hurry off as if nothing had happened.
Winston Churchill
... then the Unix-Gods created "man" ...
- 11-23-2008 #6Just Joined!
- Join Date
- Nov 2008
- Posts
- 5
oh, i didn't know there was a homework rule.. sorry everyone
I worked on that for a long time, I wouldn't have posted it if I wasn't at a dead-end. It all turned out to be a simple eval + double quotes.
- 11-23-2008 #7
That's OK, I think how you phrased your question on the previous post was acceptable.
Your second post (this one) sounded like you wanted us to give you the whole thing.
Men occasionally stumble over the truth,
but most of them pick themselves up
and hurry off as if nothing had happened.
Winston Churchill
... then the Unix-Gods created "man" ...


Reply With Quote