## echo variable problem

echo variable problem
# 1
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: "
print_var \$num
 sabina View Public Profile for sabina Find all posts by sabina
# 2
02-24-2005
echo TEST_\$1
 bhargav View Public Profile for bhargav Find all posts by bhargav
# 3
02-24-2005
This prints

TEST_1

I want it to print the value of TEST_1

10.2.3.4

Thanks,
Sabina
 sabina View Public Profile for sabina Find all posts by sabina
# 4
02-24-2005
eval echo \\${TEST}_\${num}
 vgersh99 View Public Profile for vgersh99 Find all posts by vgersh99
# 5
02-24-2005
Quote:
Originally Posted by vgersh99
eval echo \\${TEST}_\${num}
Close...
eval echo \\${TEST_\${num}}
or
eval echo \\$TEST_\${num}
 Perderabo View Public Profile for Perderabo Find all posts by Perderabo
# 6
02-24-2005
Quote:
Originally Posted by Perderabo
Close...
eval echo \\${TEST_\${num}}
or
eval echo \\$TEST_\${num}
right - thanks.
 vgersh99 View Public Profile for vgersh99 Find all posts by vgersh99
# 7
02-24-2005
Thanks,

Sabina
 sabina View Public Profile for sabina Find all posts by sabina

Test Your Knowledge in Computers #590
Difficulty: Easy
In a linear search algorithm, the input size is the number of elements in the collection (n) divided by 2.
True or False?

## 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...

## 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 : ...

## 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...

## 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...

## 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

## 6. Shell Programming and Scripting

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...

## 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...

## 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...

## 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:

## 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...