- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Setting a Var= to a variable that is increment...
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
тАО06-21-2005 09:14 AM
тАО06-21-2005 09:14 AM
Setting a Var= to a variable that is incremented in for loop.
i=1
for me in myfile
do
MYVAR$i=`who -u | grep $me'
ME$i=$MYVAR$i <
done
probably over thinking this one...any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2005 09:28 AM
тАО06-21-2005 09:28 AM
Re: Setting a Var= to a variable that is incremented in for loop.
example command
# for i in 1 2 3
> do
> let a[$i]=$i+$i
> echo ${a[$i]}
> done
2
4
6
so, yours should look like
i=1
for me in myfile
do
MYVAR[$i]=`who -u | grep $me'
ME[$i]=$MYVAR[$i]
let i=$i+1
done
now you have series of variables as follows
ME[1]="some string"
ME[2]="some other string"
...
ME[n]="yet another string"
to do whatever your heart desires
to reference them, use the following notation:
string=${ME[$i]}
where i is your array index
hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2005 09:32 AM
тАО06-21-2005 09:32 AM
Re: Setting a Var= to a variable that is incremented in for loop.
t=`who -u | grep $me`
eval "MYVAR$i=$t"
eval "ME$i=$MYVAR$i"
HTH
-- Rod Hills
- Tags:
- eval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2005 04:39 PM
тАО06-21-2005 04:39 PM
Re: Setting a Var= to a variable that is incremented in for loop.
- is myfile meant to be a file with names perhaps? In that case check out grep -f and reading its output: who | grep -f myfile | ...
If/when `who -u | grep $me` returns multple lines, should those become individually named/numbered variables?
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2005 05:41 PM
тАО06-21-2005 05:41 PM
Re: Setting a Var= to a variable that is incremented in for loop.
#!/bin/ksh
i=1
while read me;
do
let VAR[$i]=`who -u | grep $me`
let ME[$i]=${VAR[$i]}
let i=i+1
done < myfile
It will do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2005 09:37 PM
тАО06-21-2005 09:37 PM
Re: Setting a Var= to a variable that is incremented in for loop.
you last line should look like
i=`expr $i +1`
Anyway pls let us know what is your aim behind this. maybe a simple script would solve the problem
Cheers !!!
eknath