Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 31 Aug 2014, 06:47
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
How to pass Named Variable to script
Moderators: Flash, Ian, JohnMurga
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count_1  
Author Message
kethd

Joined: 20 Oct 2005
Posts: 451
Location: Boston MA USA

PostPosted: Thu 22 Dec 2005, 09:08    Post_subject:  How to pass Named Variable to script  

How to pass named variables to ash/bash shell scripts

If you want to test a shell script that uses named variables, with values passed in from the outside, things are somewhat confusing.

If you just set a value:
# SBUG=trying
and then run your script:
# ash testscript
you'll be surprised to find that $SBUG is null, empty.

The reason is that the value that you set exists only at that level, and your testscript ran as a nested sub-shell, one level down.

To make this work, use the export command:
# export SBUG=newval -- or just:
# export SBUG
which will make the named variable available at that level, and all nested levels below (but not at any levels above). If you change the value at any of nested levels below, the new value will be inherited by any levels below that, but levels above will retain their previous values.

You can view named variables with the set or env commands. The set command gives a nice ordered list, but it includes both "environment" variables and some kind of "other" values. The env command seems to show a more limited list, in hodge-podge order. Using these commands inside of test scripts can help you understand what values they are seeing.

(This is not the standard way to pass arguments to scripts. The normal way is with in-line positional arguments, $1 $2 $3 etc.)
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count_1  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0383s ][ Queries: 11 (0.0053s) ][ GZIP on ]