- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Search in ksh array
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
04-18-2004 08:20 PM
04-18-2004 08:20 PM
Search in ksh array
I have an array containing string entries
arr[0]=Entry1
arr[1]=Entry2
.
When given any string I need to check if that string is present in this array. In there any way of doing it apart from looping over the whole array.
Like in TCL we have,"array exists
Any ideas or suggestions most welcome.
- Praveen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2004 08:38 PM
04-18-2004 08:38 PM
Re: Search in ksh array
testa[0]=first
testa[1]=second
echo ${testa[1]}
echo ${testa[*]} | grep first >/dev/null
echo $?
echo ${testa[*]} | grep third >/dev/null
echo $?
It will give following output
second
0 # true
1 # false
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2004 08:49 PM
04-18-2004 08:49 PM
Re: Search in ksh array
if `echo ${arr[*]} | grep searchstring \
2>&1 >/dev/null`
then
go looping
fi
[i hope the [*] was the correct way to address every value in the array, can't test it right now.]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2004 08:59 PM
04-18-2004 08:59 PM
Re: Search in ksh array
testa[0]=first
testa[1]=second
if `echo ${testa[*]} | grep ${testa[0]} > /dev/null`
then
echo "successful"
fi
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2004 09:01 PM
04-18-2004 09:01 PM
Re: Search in ksh array
grep -x
won't hurt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2004 09:11 PM
04-18-2004 09:11 PM
Re: Search in ksh array
testa[0]=first
testa[1]=second
if `echo ${testa[*]} | grep -x ${testa[0]} > /dev/null`
then
echo "successful"
else
echo "unsuccessful"
fi
sks