Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

KSH shell arrays

Status
Not open for further replies.

alfie002

Technical User
Mar 3, 2004
121
GB
Hello all,

I am currently using an array within an ksh script. I have included an example of the array definition as follows;

target[0]="OVsPMD ovsessionmgr ovtrapd ovactiond ovalarmsrv pmd genannosrvr httpd ovrequested ovdbcheck"

In this a space defines the values in the array. Is there any way to change this from a space to another character ?

Thanks

Alf
 

Try:
Code:
tmp=`echo "${target[0]}"|tr ' ' '~'`
target[0]="$tmp"

[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Hi Alf,

With this syntax you are not really using an array at all, just assigning all of the values to index 0 of the array. If you really want target[0] to be set to "OvSMPD", target[1] to be set to "ovsessionmgr", etc. you need to do something like this:

[tt]set -A target OVsPMD ovsessionmgr ovtrapd ovactiond ovalarmsrv pmd genannosrvr httpd ovrequested ovdbcheck[/tt]

To use a different field separater is a little more tricky, this should work:

[tt]temptarget="OVsPMD-ovsessionmgr-ovtrapd-ovactiond-ovalarmsrv-pmd-genannosrvr-httpd-ovrequested-ovdbcheck"
IFS=-
set -A target $temptarget
unset IFS[/tt]

I'm not sure why you can't just set IFS and then set -A target=OVsPMD-ovesessionmgr-etc; I had to do it in two steps like the example above.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top