LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-14-2010, 07:21 AM   #1
Dru-Jitsu
Member
 
Registered: Jun 2010
Posts: 38

Rep: Reputation: 15
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!

Last edited by pixellany; 07-14-2010 at 07:27 AM.
 
Old 07-14-2010, 07:26 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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.
 
Old 07-14-2010, 07:29 AM   #3
Dru-Jitsu
Member
 
Registered: Jun 2010
Posts: 38

Original Poster
Rep: Reputation: 15
Yeah, thats correct. Whats in blue is what I get when running the commands I am told to.
 
Old 07-14-2010, 07:29 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Why the comma?
Try the commands with no commas and see what happens!
 
Old 07-14-2010, 07:31 AM   #5
Dru-Jitsu
Member
 
Registered: Jun 2010
Posts: 38

Original Poster
Rep: Reputation: 15
are you talking about when I echo it?
 
Old 07-14-2010, 07:40 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,505

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
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
 
1 members found this post helpful.
Old 07-14-2010, 07:51 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by Dru-Jitsu View Post
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.
 
1 members found this post helpful.
Old 07-14-2010, 08:02 AM   #8
Dru-Jitsu
Member
 
Registered: Jun 2010
Posts: 38

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
Try the commands with no commas and see what happens!
Doing this gives me the same output minus all the commas
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Some help with some basic scripting needed please utw-mephisto Linux - Newbie 13 01-26-2010 07:27 PM
Basic Scripting karlochacon Linux - Newbie 6 11-12-2009 06:22 PM
Basic shell scripting help zipper777 Linux - Newbie 6 03-13-2006 12:58 PM
Basic bach scripting BruceC Linux - Newbie 4 02-25-2005 09:31 AM
very basic scripting question spatter9999 Programming 3 09-18-2003 01:36 AM


All times are GMT -5. The time now is 09:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration