- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: variable substitution
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2000 08:05 AM
12-01-2000 08:05 AM
xxxa=test1
xxxb=test2
xxxc=test3
for i in a b c
do
echo "$xxx$i"
done
where I want the result to be test1, test2, test3 (not xxxa, xxxb, xxxc). Can anyone help me with the syntax for the echo line please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2000 08:11 AM
12-01-2000 08:11 AM
Re: variable substitution
a=test1
b=test2
c=test3
for i in $a $b $c
do
echo "$i"
done
The variables you should specify with $xxxa etc.
Is this what you want?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2000 08:21 AM
12-01-2000 08:21 AM
Re: variable substitution
Not quite as I don't want to specify the whole variable in the for statement. The previously assigned variables need to be longer and I will actually be using a number to reference them in a loop i.e. disk1 disk2 disk3 etc and the loop count will be used for the number i.e. for i in 1 2 3 4.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2000 08:22 AM
12-01-2000 08:22 AM
Re: variable substitution
echo "${xxx}${i}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2000 08:28 AM
12-01-2000 08:28 AM
Re: variable substitution
Thanks, but it doesn't fix the problem as I get a,b,c rather than the contents of xxxa, xxxb, xxxc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2000 09:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2000 09:45 AM
12-01-2000 09:45 AM
Re: variable substitution
xxxa=test1
xxxb=test2
xxxc=test3
a=$xxxa
b=$xxxb
c=$xxxc
for i in $a $b $c
do
echo "$i"
done
Good luck
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2000 11:00 AM
12-01-2000 11:00 AM
Re: variable substitution
Assign the variable as follows:
xxx[1]=tiger ; xxx[2]=lion ; xxx[3]=cat
If you assign as above then the following would do the job:
for i in ${xxx[@]} ; do
echo $i
done
Above should display:
tiger
lion
cat
Best of luck,
Pramod
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2000 11:13 AM
12-01-2000 11:13 AM
Re: variable substitution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2000 04:27 AM
12-02-2000 04:27 AM
Re: variable substitution
xxxa=1
xxxb=2
xxxc=3
for i in $a $b $c ; do
eval echo "\$xxx$i"
done
The eval tells the shell to expand all of the variables prior to excecuting the "echo".
This is why Kenneths example works!
Regards,
Shannon