- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: > k=1 ; val$k=3 # how can i accomplish this?
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
тАО11-02-2001 12:40 PM
тАО11-02-2001 12:40 PM
well,
is there any way to achieve this?
------------------------------------
k=1
for i in p q r
do
ab$k=$i
done
> echo "ab1=$ab1" # ab1=p
-------------------------------------
so that i can store each values in
ab1, ab2, ab3 so on ..
or
in awk or gawk
is there any way that i can export value
in awk program?
like this?
--------------------------------------
awk '{n=1} {print n}'
>echo "n=$n" #n=1
--------------------------------------
thx..
Eugene Kim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-02-2001 12:46 PM
тАО11-02-2001 12:46 PM
SolutionHowever, this would work if you used an array such as:
ab[${i}]=p
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-03-2001 04:50 PM
тАО11-03-2001 04:50 PM
Re: > k=1 ; val$k=3 # how can i accomplish this?
Sure, there's always a trick that does it in unix. :)
k=1
for i in p q r
do
cmd=`echo ab$k=$i`
eval $cmd
done
That should solve your problem.
Cheers,
Paga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-04-2001 12:29 PM
тАО11-04-2001 12:29 PM
Re: > k=1 ; val$k=3 # how can i accomplish this?
Sure :
var=`awk '{n=1} {print n}'`
Also, you can accomplish a lot more and have greater flexibility y writing your scipts in perl.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2001 06:19 AM
тАО11-05-2001 06:19 AM
Re: > k=1 ; val$k=3 # how can i accomplish this?
your basic problem is, that when the shell evaluates your variable, it just passed the part that usally sets variables (which is built in) and serches for commands.
If you cann effort to export the variable,
simply do it, and your script will work.
See this from Red Hat 6.1
$ a=3
$ export ab$a=4
$ echo $ab3
4
$
Hope this helps
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-06-2001 04:01 PM
тАО11-06-2001 04:01 PM
Re: > k=1 ; val$k=3 # how can i accomplish this?
i've searched all bash manual for this question .. (howto in linuxdoc and bash manual in www.gnu.org)
this is awesome..
where do i have to go besides the above two sites to find answers that you provide?
(at least, i want to how the codes you provide work..)
and .. about awk question..
what if i have 2 or more variables in awk process?
for example..
awk '$1 ~ /-/ { option=option$1}
$1 !` /-/ { argument=argument$`}'
is there any way to use variable option & argument outside of awk?
here's what i do
=====================
mystring=`echo $input |
awk 'BEGIN { RS=" " }
$1 ~ /-/ { option=option$1 }
$1 !~ /-/ { arg=arg" "$1 }
END { print option; print arg }' | sed 's/-/ /g'` #any way to store value which is visible outside awk?
option=`echo "$mystring" | sed -n '1p'`
arg=`echo "$mystring" | sed -n '2p'`
=====================
any more elegant way?
--;
thx
Eugene Kim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2001 12:57 PM
тАО11-07-2001 12:57 PM
Re: > k=1 ; val$k=3 # how can i accomplish this?
and..
here's what i figured out by myself
another way to do
ab$c=3
when c=1
---------------------
c=1
read ab$c << eof
3
eof
echo $abc
3
---------------------
:)
Eugene Kim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2001 09:19 AM
тАО11-09-2001 09:19 AM
Re: > k=1 ; val$k=3 # how can i accomplish this?
well "awk" is a very complex tool, I would not expect everything from the man-pages. Search amazon for awk. This one is quite OK
http://www.amazon.com/exec/obidos/ASIN/020107981X/qid=1005325986/sr=2-2/ref=sr_2_11_2/107-9238346-8792502
But from the man-pages, you might learn as well, there are system-variables like:
Built-in Variables
Gawk's built-in variables are:
ARGC The number of command line arguments (does not include options to gawk, or the program source).
ARGIND The index in ARGV of the current file being processed.
ARGV Array of command line arguments. The array is indexed from 0 to ARGC - 1. Dynamically changing the
contents of ARGV can control the files used for data.
CONVFMT The conversion format for numbers, "%.6g", by default.
ENVIRON An array containing the values of the current environment. The array is indexed by the environment
variables, each element being the value of that variable (e.g., ENVIRON["HOME"] might be
/home/arnold). Changing this array does not affect the environment seen by programs which gawk
spawns via redirection or the system() function. (This may change in a future version of gawk.)
Of which ENVIRON and ARGV might be of most interest. Esp. ARGV[1], ARGV[2] ... to access the parameters.
As far as your question concerning "bash" is required, I have to admit, I did not look up this behavior. I learned this loooooong time ago, when there was an old operating system called DOS, that has a completely diffrent behavior upon expanding wildcards (it simply does not do it!).
When I switched to UNIX, there where fundamental diffrences between a "sh" and "command.com" that I figured out more closely, than anyone new to "sh" would do today.
Have fun learning "awk" it is real fun.
So long
Volker
BTW: would be nice if you would assign some points.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-09-2001 07:55 PM
тАО11-09-2001 07:55 PM
Re: > k=1 ; val$k=3 # how can i accomplish this?
i'd like to give 10 points to all the people who helped me.
this konquer browser gives me 404 nonfound(?) error
...even netscape doesn't work --;
i'll make sure i'll give u points when i logged on with windows..
..
:)
Thx again