Sponsored Content
Top Forums Shell Programming and Scripting variable part of variable name Post 302161685 by Smoker on Friday 25th of January 2008 12:11:40 PM
Old 01-25-2008
Quote:
Originally Posted by KittyWu
Hi,

I'm not sure this answer suits to your request (if you meant
"how to display/store or use the resulting value", then this
should help...).

First, the 2 first lines sound correct for both defining a variable
and assigning a value to it:
me@host> A="PRE"
me@host> eval ${A}_DAY=`date +%d`

In order to solve this kind of trouble, I usually use this
kind of syntax:
me@host> DAY_VALUE=$(unalias echo; eval echo $"${A}_DAY")
me@host> echo ${DAY_VALUE}
me@host> 25

Hope it helps,
Christophe
Ran into a couple of other ways...

echo $(eval echo \$${A}_DAY)
eval echo "\$${A}_DAY"

Thank You for your answer Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies

2. Shell Programming and Scripting

Repacing part of string with a variable

I have following strings in a file DUPTASMTRMMBAL,20070416200704160117232101172321,,,,,,,@@@Y DUPTASMTRMMCON,20070416200704160127189901271899,,,,,,,@@@Y DUPTASMTRMMHG,,20070416200704160112051001120510,,,,,,,@@@Y What i need to do is replace the date 20070416 with anoth date which is stored in... (4 Replies)
Discussion started by: divz
4 Replies

3. Shell Programming and Scripting

direction symbol in a variable as part of the command

Hi, How can I get this to work? #!/bin/ksh if ; then direction=">>" else direction=">" fi cat some_file_name $direction temp.txt exit This shell script is not happy with using "$direction" opposed to ">" or ">>". Thanks. (5 Replies)
Discussion started by: peterloo
5 Replies

4. Shell Programming and Scripting

Copy part of a variable

Hi, i was using a input file to get the last line of the file.But now i have stored the values from the file to a variable and want the last line from the variable . Slightly confused on how to extract that data from the variable. previous code, cat input.txt <TIME>00:15:48</TIME>... (2 Replies)
Discussion started by: Shellslave
2 Replies

5. Shell Programming and Scripting

Variable of Content From Part of Other File

I may not being doing this description justice, but I'll give it a try. I created a mailx script; there will be several messages using the same script where the only difference is the content. So I figured I'd make the content of the message a variable retrieved from a separate file. I have five... (5 Replies)
Discussion started by: royarellano
5 Replies

6. Shell Programming and Scripting

How read the part of the string into a variable?

Hi, I'm using bash and brand new to shell script. I would like to do the following. I have a string which is "UPDATE=1.0". I would like to read the value "1.0" alone in a variable. i.e the things afer "=" How do I do that? Thanks, (1 Reply)
Discussion started by: scriptfriend
1 Replies

7. UNIX for Dummies Questions & Answers

Removing Part of a variable based on a pattern

Hi All, I am writing a script to work with files in a folder. The files are all in the following patterns (without quotes): "some filename - NxNN - the end.YYY" or "some filename - NNxNN - the end.YYY" Where N = a single number and YYY is the extension. Basically what I want... (5 Replies)
Discussion started by: sgtbobie
5 Replies

8. Shell Programming and Scripting

Using the part of a line as a variable?

Hello Friends, I need a command (or script line) that allows me to use of a part of line (given by me) as a variable. Let us assume the name of the command is MYCMD. When I type MYCMD fish://mfong@vhl.gov.nd/homefolder/hhk/ADS/ it must do the following job cd /homefolder/hhk/ADS/ ... (18 Replies)
Discussion started by: rpf
18 Replies

9. Shell Programming and Scripting

use some part of variable value to replace ../../ values in a file

hi, i have variable value as follows val="/dir1/dir2/dir3/dir4/dir5/dir6/file1" it is pointing to some file location. and i have another file as ../../dir4/file3 ../../dir4/dir5/file4 ../../dir7/file5 i want the output as /dir1/dir2/dir3/dir4/file3 (7 Replies)
Discussion started by: snreddy_gopu
7 Replies

10. Programming

PASSING PART OF FILE CONTENT TO VARIABLE

All, I have a log file containing lots of data now i want to extract all text between block below(names) without the title or end pattern but only names, ++++START++++ SCOTT TIGER HENRY PAUL JARED OTIENO OMOLLO JA NIGERIA ++++END++++ the names i want to return and store in a variable in... (1 Reply)
Discussion started by: Scott2000
1 Replies
printenv(1B)					     SunOS/BSD Compatibility Package Commands					      printenv(1B)

NAME
printenv - display environment variables currently set SYNOPSIS
/usr/ucb/printenv [variable] DESCRIPTION
printenv prints out the values of the variables in the environment. If a variable is specified, only its value is printed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), sh(1), stty(1), tset(1B), attributes(5), environ(5) DIAGNOSTICS
If a variable is specified and it is not defined in the environment, printenv returns an exit status of 1. SunOS 5.10 14 Sep 1992 printenv(1B)
All times are GMT -4. The time now is 06:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy