- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: KSH syntax
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
12-06-2002 02:17 AM
12-06-2002 02:17 AM
Tanks in dvance.
Andrej
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2002 02:33 AM
12-06-2002 02:33 AM
Re: KSH syntax
If you don't like 'else if' constructs (I don't) then using a function makes it easier to code, something like...
#!/usr/bin/sh
function process_file {
if grep -q
then
return
fi
if grep -q
then
return
fi
if grep -q
then
return
fi
if grep -q
then
return
fi
print "No action for file ${1}" >&2
}
process_file
Otherwise you could have...
#!/usr/bin/sh
# assume file_name is in ${1}
if grep -q
then
elif grep -q
then
elif grep -q
then
elif grep -q
then
fi
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2002 02:42 AM
12-06-2002 02:42 AM
Solutionusing case, you could do the following:
#!/usr/bin/ksh
file=$1
S1=string1
S2=string2
S3=string3
S4=string4
for a in 1 2 3 4; do
grep -q `eval echo '$S'$a` $file && FLAG=$a
done
case $FLAG
in
1)
echo file type 1
;;
2)
echo file type 2
;;
3)
echo file type 3
;;
4)
echo file type 4
;;
*)
echo unknown file type
;;
esac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2002 02:54 AM
12-06-2002 02:54 AM
Re: KSH syntax
what's about this:
grep -il "uniq1" * | xargs
grep -il "uniq2" * | xargs
...
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2002 03:30 AM
12-06-2002 03:30 AM
Re: KSH syntax
# cat > test
1234
# cat > test2
1245
# cat > test.ksh
#! /usr/bin/ksh
for i in test*
do
if grep -q 1234 $i
then
echo "$i contains 1234"
elif grep -q 1245 $i
then
echo "$i contains 1245"
fi
done
# chmod 777 test.ksh
# ./test.ksh
test contains 1234
test.ksh contains 1234
test2 contains 1245
Francois-Xavier