Problem in script when using variables

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Problem in script when using variables
# 1  
Problem in script when using variables

The AppName may be TCS/HCL/SCB.
For All the above 3 i ill have exported TCSDIR/HCLDIR/SCBDIR in .profile with some path.
i'm cnstruct the path in script and trying to cd $VARIABLE, it shows "not found".

Any solution for this....?

> AppName="TCS"
> echo $AppName
> start_path="\$${AppName}DIR/src"
> echo $start_path
> cd $start_path
ksh: $TCSDIR/src:  not found
> cd $TCSDIR/src

# 2  
Assuming the name of the directory is /TCSDIR/scr


# 3  
$TCSDIR is the env variable set in my .profile

so i'm creating that based on the input in my script.
When i'm using that in script i'm getting issue.

$TCSDIR is /tmp/TCS_TEMP which is exported in .profile
# 4  
You need to use eval to expand a variable inside another variable.

eval echo $start_path

# 5  
Thanks, Its working.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #391
Difficulty: Medium
Darwin, the open source subset of macOS, has behavior that can be set to comply with UNIX 03.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with variables and bash script

From the command line: dions-air:scripts dion$ ls -l /Users/dion/Library/Application\ Support/Garmin/Devices/3816821036/History/2014-06-07-055251.TCX -rw-r--r-- 1 dion staff 157934 7 Jun 06:55 /Users/dion/Library/Application Support/Garmin/Devices/3816821036/History/2014-06-07-055251.TCXworks... (2 Replies)
Discussion started by: dionbl
2 Replies

2. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

3. Shell Programming and Scripting

Problem in Global variables in shell script

hi, i have a shell script which calls another shell which in turn calls another shell script. echo "In" FILENAME="original.txt" # LINE 1 DST_FILENAME=$FILENAME # LINE 2 echo "FILENAME = {$FILENAME}" echo "DST_FILENAME =... (3 Replies)
Discussion started by: Little
3 Replies

4. Shell Programming and Scripting

Awk script problem - Variables Causing Issue

can someone please explain to me what i'm doing wrong with this code: WELT=$(awk '(($1 ~ "^${caag}$") || ($2 ~ "^${caag}$"))' /tmp/Compare.TEXT) when run from the command line, it works. but it seems to be having a problem doing the comparison when variables are involved. i tested from... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Emergency UNIX and Linux Support

Problem setting environment variables from script

Hi all! I know that environment variables can be set on the .bashrc file, but I need to set them from a sh script. I saw a lot of websites that teach this but it doesn't work for me. #!/bin/sh DEKTOP=$DESKTOP=:/home/rrodrigues/Desktop export DESKTOP if I do echo $DESKTOP returns me... (10 Replies)
Discussion started by: ruben.rodrigues
10 Replies

6. Shell Programming and Scripting

Problem while concatenating variables in shell script

Hi folks, I am facing problem when I concat variables with the string. Value for 'JDBC_CLASSES' variable looks malformed (/classes12.zip2.0KAGES) But, my expected result for 'JDBC_CLASSES' is /opt/API-R111/PACKAGES/jdbc/ORACLE9.2.0/ Am I missing anything here? My... (10 Replies)
Discussion started by: Adhil
10 Replies

7. Shell Programming and Scripting

problem using variables in bash script

I am using variable to give the location of the file I am using but I get error. Here is the code: LogFile=/tmp/ echo -e "could not close the service - error number $error \n" > $LogFile well this is not all the code but is enough because the problem start when I try to use the... (3 Replies)
Discussion started by: programAngel
3 Replies

8. Shell Programming and Scripting

Execution problem with grep script (2 variables)

#!\bin\sh TEST=test.log GREP=\usr\bin\grep $GREP -i 'dog\|cat' ${TEST} Why doesn't grep run at all? (10 Replies)
Discussion started by: jazzaddict
10 Replies

9. Shell Programming and Scripting

problem accessing Multiple Variables from C Program to a Shell script

program name--test #!/bin/bash output1=`/home/user/a.c` output2=`/home/user/a.c` k=`$output1 + 1` m=`$output2 + 1` echo $k echo $m --------------------------------------------------------------------------- prgram name--a.c #include<stdio.h> int main() (1 Reply)
Discussion started by: sameworld1980
1 Replies

10. Shell Programming and Scripting

problem with variables

hi all , i wanted to know if someone knows how can i use a variable inside another variable e.g. #!/bin/csh foreach test(1 2 3) set sta_$test = "2" ##now its the problem i want to echo the new var #$sta_$test , each time with anothe num ($test = 1... (2 Replies)
Discussion started by: udi
2 Replies

Featured Tech Videos