UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 27th, 2012, 11:09 PM
clinton_eg clinton_eg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 clinton_eg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 4 sec
Reputation Power: 0
How to use Local Variables in unix?

i have created the below UNIX script to learn how to use Variables, however the output is blank. could anyone let me know what is wrong with the below script please.

#! /bin/sh
# test script
set Var1 = "Test"
echo $Var1

Reply With Quote
  #2  
Old December 28th, 2012, 01:17 AM
DonR DonR is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 458 DonR User rank is Captain (20000 - 30000 Reputation Level)DonR User rank is Captain (20000 - 30000 Reputation Level)DonR User rank is Captain (20000 - 30000 Reputation Level)DonR User rank is Captain (20000 - 30000 Reputation Level)DonR User rank is Captain (20000 - 30000 Reputation Level)DonR User rank is Captain (20000 - 30000 Reputation Level)DonR User rank is Captain (20000 - 30000 Reputation Level)DonR User rank is Captain (20000 - 30000 Reputation Level)DonR User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 29722 Folding Title: Starter FolderFolding Points: 29722 Folding Title: Starter Folder
Time spent in forums: 2 Weeks 1 Day 21 h 32 m 46 sec
Reputation Power: 216
you don't need to use set.

working example is this
Code:
#!/bin/sh
#test script
Var1="Test"
echo $Var1

Reply With Quote
  #3  
Old December 28th, 2012, 04:37 AM
clinton_eg clinton_eg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 clinton_eg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 4 sec
Reputation Power: 0
Quote:
Originally Posted by DonR
you don't need to use set.

working example is this
Code:
#!/bin/sh
#test script
Var1="Test"
echo $Var1


Thanks DonR, tried using the code you advised, i get the following error

$ ./t_script
./t_script: line 3: Var1: command not found

Reply With Quote
  #4  
Old December 28th, 2012, 04:48 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,107 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 3 h 57 m 31 sec
Reputation Power: 1485
I susoect you will have spaces in the line ..

Code:
Var1  =   "value"

(exaggaerated number of spaces to make it clear!)
where it shoule not have spaces:
Code:
Var1="value"
Comments on this post
aitken325i agrees!
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
  #5  
Old December 28th, 2012, 04:57 AM
clinton_eg clinton_eg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 clinton_eg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 4 sec
Reputation Power: 0
Quote:
Originally Posted by SimonJM
I susoect you will have spaces in the line ..

Code:
Var1  =   "value"

(exaggaerated number of spaces to make it clear!)
where it shoule not have spaces:
Code:
Var1="value"


Thanks Simon1, you are correct.. i removed the spaces and it worked

DonR - Sorry did not notice that your code excluded the blank spaces.. if i had to literally copy and paste it would have worked

Last edited by clinton_eg : December 28th, 2012 at 05:03 AM. Reason: Added a comment to DonR

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > How to use Local Variables in unix?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap