echo variable problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting echo variable problem
# 1  
Old 02-24-2005
echo variable problem

hi

I have say five variable.

I would ask the user which one they want me to print and then print accordingly.


TEST_1='10.2.3.4'
TEST_2='11.2.3.5'
TEST_3='12.2.3.5'
TEST_4='13.2.3.5'
TEST_5='14.2.3.5'

print_var()
{
echo "Accessing var num $1"
echo TEST$1
#??? But How do I print the value of say TEST_1 here base on user input

}
echo -n "Please enter the var num: "
read num
print_var $num
# 2  
Old 02-24-2005
echo TEST_$1
# 3  
Old 02-24-2005
This prints

TEST_1

I want it to print the value of TEST_1

10.2.3.4


Thanks,
Sabina
# 4  
Old 02-24-2005
eval echo \${TEST}_${num}
# 5  
Old 02-24-2005
Quote:
Originally Posted by vgersh99
eval echo \${TEST}_${num}
Close...
eval echo \${TEST_${num}}
or
eval echo \$TEST_${num}
# 6  
Old 02-24-2005
Quote:
Originally Posted by Perderabo
Close...
eval echo \${TEST_${num}}
or
eval echo \$TEST_${num}
right - thanks.
# 7  
Old 02-24-2005
Thanks,

Sabina
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo awk output from its variable

Stumped with the formatting of the awk output when used with variables, e.g.: awk -F, 'BEGIN {OFS=","} print {$2,$3,$4}' $infile1 produces the desired output (with rows), but when echoing the variable below, the output is one continuous line var1=$(awk -F, 'BEGIN {OFS=","} print... (4 Replies)
Discussion started by: ux4me
4 Replies

2. Shell Programming and Scripting

Echo not displaying variable in If-Else condition

if then echo "Entry Valid : ${x_oug}" else echo "Entry Invalid : " 0 fi In the above code the 3rd line is not working... it does not print anything I tried following as well .. but no luck! echo "Entry Valid : ... (13 Replies)
Discussion started by: Chetanz
13 Replies

3. Shell Programming and Scripting

echo the NAME of the variable

#!/bin/bash varA="AAA1" varB="BBB2" varC="CCC3" for proccx in $varA $varB $varC do echo "the current name is ????? , the value is $proccx" echo " " done #end of script I want the output to look something like this: the current name is varA, the value is AAA1 the current name is... (5 Replies)
Discussion started by: ajp7701
5 Replies

4. Shell Programming and Scripting

Problem with variable ECHO $((SED...

Hi, I'm new here so I want to say hello to everyone first! I searched google and this forum for a similar problem, but wasn't successful #! /bin/bash I'm trying to output (echo) n lines of a text file to the screen (later into another file). But I have problem with the sed command, it won't... (1 Reply)
Discussion started by: studiologe
1 Replies

5. UNIX for Dummies Questions & Answers

How to assign echo in variable

I've testing the following code: echo test.txt | cut -d . -f1and get the output "text" So why can't i assign the command to a variable? VAR='"echo test.txt | cut -d . -f1"' echo $VAR (5 Replies)
Discussion started by: jl487
5 Replies

6. Shell Programming and Scripting

read variable after echo

Hi, i want to create an user-friendly script where you are asked for two numbers. i would like that these two number to be separated with "--" for example, but i can't figure out how to do this. for example read -p "Insert lowest and highest value: " min ; echo -n "-- "; read max so... (3 Replies)
Discussion started by: ezitoc
3 Replies

7. Shell Programming and Scripting

echo multiple variable with calculation

$total=500 echo "scale=2; $val1*100/$total" | bc echo "scale=2; $val2*100*100/$total" | bc echo "scale=2; $val3*100/$total" | bc I want to make the above code to be accomplish in a single echo line. For instance output:21.3, 44.2, 51.6 How to achieve that, some one please help, i just... (5 Replies)
Discussion started by: alvin0618
5 Replies

8. Shell Programming and Scripting

calling a variable to echo to a log

Hi everyone, I am trying to create a simple batch file to make SQL backups. this part of it works fine. Currently the script can mysql dump the databases, compress them, delete the .sql, compress the individual tar.gz into one larger one, delete the smaller files, encrypt the final tar.gz and... (1 Reply)
Discussion started by: luma
1 Replies

9. Shell Programming and Scripting

assigning variable value using echo

I am modifying an existing script and it has the following line: export SomeEnvVar=`echo ${SomeLocalVar}` Why wouldn't it just read: export SomeEnvVar=${SomeLocalVar} Is there some reason to use echo instead of a direct assignment? :confused: (2 Replies)
Discussion started by: shellburger
2 Replies

10. UNIX for Dummies Questions & Answers

Display from a variable using echo.

I have a variable that is outputting a lot of space. here has been 45 lines returned ... how can I remove the spaces between the "been and the 45" CODE: fil_len=`wc -l < coshb.txt` if ; then cat coshb.txt | more echo " " echo "There has been ${fil_len} lines... (4 Replies)
Discussion started by: jagannatha
4 Replies
Login or Register to Ask a Question