Find the answer to your Linux question:
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 ...
  1. #1
    Just 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?

  2. #2
    Linux User dxqcanada's Avatar
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    259
    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" ...

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    5
    no, i don't.. there is a rule?

  4. #4
    Just 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

  5. #5
    Linux User dxqcanada's Avatar
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    259
    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" ...

  6. #6
    Just 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.

  7. #7
    Linux User dxqcanada's Avatar
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    259
    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" ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...