LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Basic Scripting help (https://www.linuxquestions.org/questions/linux-newbie-8/basic-scripting-help-819758/)

Dru-Jitsu 07-14-2010 07:21 AM

Basic Scripting help
 
8. Create a local variable within your shell by typing the command VAR_ONE=variable1. Create an environment variable by typing the command export VAR_TWO=variable2.

Run the command echo "$VAR_ONE, $VAR_TWO", what output appears?
Answer: Obviously when I run this I get variable1,variable2


9. Create a shell script called echo.bash that contains the following lines:

VAR_3=three
export VAR_4=four
echo "$VAR_ONE, $VAR_TWO, $VAR_3, $VAR_4"

Give the script execute permissions and execute it by running ./echo.bash. Record the output of the command. (Note, this command requires the variables VAR_ONE and VAR_TWO to exist from the previous question.)
Answer: , variable2, three, four (why the comma as the first variable? is that because variable1 was not exported?

10. Run the command echo "$VAR_3, $VAR_4" do the variables VAR_3 and VAR_4 exist in your current shell?
Answer: , (Again, why just a comma? because neither was exported to the child process?)

Anyone that can explain these a little, woule be awesome!

pixellany 07-14-2010 07:26 AM

Dru*;

At first glance, I thought you had posted a cut and paste homework assignment without comment. I'll highlight what appear to be your comments, but please check to see that I did it correctly.

Dru-Jitsu 07-14-2010 07:29 AM

Yeah, thats correct. Whats in blue is what I get when running the commands I am told to.

pixellany 07-14-2010 07:29 AM

Quote:

Why the comma?
Try the commands with no commas and see what happens!

Dru-Jitsu 07-14-2010 07:31 AM

are you talking about when I echo it?

grail 07-14-2010 07:40 AM

Quote:

Originally Posted by Dru-Jitsu
why the comma as the first variable? is that because variable1 was not exported?

Yes
Quote:

Originally Posted by Dru-Jitsu
Again, why just a comma? because neither was exported to the child process?

Not quite. For your child process idea try this:

Put echo "$VAR_3, $VAR_4" in another script called child.bash.
Now put the following line at the end of echo.bash - ./child.bash

This should help to understand the child process getting variables

pixellany 07-14-2010 07:51 AM

Quote:

Originally Posted by Dru-Jitsu (Post 4032790)
are you talking about when I echo it?

Whereever the question applies!! If you are running a command with commas, then try it without commas.

Dru-Jitsu 07-14-2010 08:02 AM

Quote:

Originally Posted by pixellany (Post 4032789)
Try the commands with no commas and see what happens!

Doing this gives me the same output minus all the commas


All times are GMT -5. The time now is 06:52 PM.