The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
set variable with another variable? c shell wxornot Shell Programming and Scripting 2 02-23-2008 03:10 PM
Replace variable with a user defined variable ce124 Shell Programming and Scripting 1 04-15-2007 02:56 PM
Variable in While Loop Nested If geass Shell Programming and Scripting 6 03-26-2007 06:09 PM
ksh: A part of variable A's name is inside of variable B, how to update A? pa3be Shell Programming and Scripting 4 03-30-2005 11:29 AM
does this variable call work--Korn morkfard UNIX for Dummies Questions & Answers 2 07-10-2001 10:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-01-2008
princelinux princelinux is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 32
Enviornment Variable in B shell (I call it nested variable)

Code:
#!/bin/sh

APP_ROOT_MODE1=/opt/app1.0
APP_ROOT_MODE2=/opt/app2.0

APP_ROOT=${APP_ROOT_${APP_MODE}}


# enviornment variable APP_MODE will be exported in the terminal where 
# we run the applciation,  its value is string - MODE1 or MODE2  
# My intension is:
# when export APP_MODE=MODE1 in terminal,  APP_ROOT is /opt/app1.0
# when export APP_MODE=MODE2 in terminal,  APP_ROOT is /opt/app2.0
But the script above does not work? Any grammar error? Any trick?

Thanks in advance
  #2 (permalink)  
Old 07-01-2008
zaxxon's Avatar
zaxxon zaxxon is online now Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Code:
Does not work
What does not work - what's the error output?

This here does not look as if it works:
Quote:
APP_ROOT=${APP_ROOT_${APP_MODE}}
Try
Code:
APP_ROOT=${APP_ROOT}_${APP_MODE}
  #3 (permalink)  
Old 07-01-2008
princelinux princelinux is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 32
The erorr message is
line 24: ${APP_ROOT_${APP_MODE}}: bad substitution


BTW, ${APP_ROOT}_${APP_MODE} is not my intention.
  #4 (permalink)  
Old 07-02-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
eval APP_ROOT=\${APP_ROOT_${APP_MODE}}
  #5 (permalink)  
Old 07-02-2008
princelinux princelinux is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 32
Thanks, Annihilannic. Yes it works.
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0