- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: nested variable access
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
Discussions
Discussions
Forums
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
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
тАО08-29-2006 01:09 AM
тАО08-29-2006 01:09 AM
nested variable access
i=2
echo \$$i
I tried different options like \$$i, ${$i}, $'$i', $"$i" etc. but nothing is working out.
Please help me do this.
- Tags:
- variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2006 01:23 AM
тАО08-29-2006 01:23 AM
Re: nested variable access
have you looked at using shift within a loop ?
"PSEUDO CODE" !
a=0
b=$1
while $a < $b
do
shift
a=a+1
done
echo $1
- Tags:
- shift
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2006 01:24 AM
тАО08-29-2006 01:24 AM
Re: nested variable access
I'd use an array:
set -A args "$@"
echo ${args[$var]}
- Tags:
- ARRAY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2006 01:28 AM
тАО08-29-2006 01:28 AM
Re: nested variable access
#!/usr/bin/sh
echo $*| awk -F' ' '{print $$1};'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2006 01:46 AM
тАО08-29-2006 01:46 AM
Re: nested variable access
#!/usr/bin/sh
set -A a "${@}"
i=2
echo "${a[${i}]}"
exit
Note that array indexing starts at 0.
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2006 01:48 AM
тАО08-29-2006 01:48 AM
Re: nested variable access
case $i in
1)
echo $1
;;
2)
echo $2
;;
3)
echo $3
;;
esac
However personally I always use getopts to process commandline argument values.
while getopts a:ishv: opt
do
case ${opt} in
a) VGM=${OPTARG}
;;
i) opt_i=true
;;
s) opt_s=true
;;
v) VG=${OPTARG}
;;
h|*) usage ${0##*/}
;;
esac
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-29-2006 09:22 AM
тАО08-29-2006 09:22 AM
Re: nested variable access
#!/bin/sh
i=2
eval echo \$$i
- Tags:
- eval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-04-2006 10:26 PM
тАО09-04-2006 10:26 PM