Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sat Jul 14, 2012 7:57 am 
Offline
Junior Member

Joined: Sun May 13, 2012 10:02 am
Posts: 20
Hi,

When creating files in my stackscript, for example:
Code:
   cat > $file << EOF
server {
   $DEP       80;
}


The stackscript variables like "$DEP" dont work. Instead I have to do this:
Code:
   local file=$1
   bash_dep="$DEP"
   cat > $file << EOF
server {
   $bash_dep       80;
}


Is this a bug, known feature or am I making a mistake? Its a bit annoying to have to do those extra equates in my code.

James

P.s Bonus question. Is it ok to use one stackscript variable within another one (i.e $VAR2 = $VAR1/folder)?


Top
   
PostPosted: Sun Jul 15, 2012 1:44 pm 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
It's possible (I'm not sure, this is kind of a tricky area of shell scripting) that the command is running in a subshell environment. If that's the case, only those variables that have the export attribute are available in the subshell. Try this:
Code:
   export DEP
   cat > $file <<EOF
server {
   $DEP       80;
}
EOF


If this does what you want, then my guess was correct and you can use any stackscript variables you want by including a line like
Code:
export FOO BAR BAZ

before you want to use the variables. If it doesn't work, then I dunno.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group