- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- strange grep behavior...
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
тАО04-13-2012 03:17 PM
тАО04-13-2012 03:17 PM
strange grep behavior...
This has me stumped... We are moving from a PA-RISC rp7440 to a new Itanuim blade server (I was the admin on the old server but moved on to another job and am just helping on the new one so I don't know all the specs). The old server was on 11v1/11.11, the new one is 11v3/11.31. The way our systems work some users get upper case login ID's and some get lower and I had a couple scripts that used this distinction to affect how they ran. To do this I would have lines like this:
echo $LOGNAME | grep -q [A-Z]
if [[ $? -eq 0 ]]
then
...
Worked fine for years on the old system. Started doing some testing on the new system and grep is not always returning the same, correct results... I have a lower case ID so the above test should fail, but it doesn't... Check out these results from some command line tests:
/home/jwolgast (p3k) <proddb> echo X${LOGNAME}X
XjwolgastX
/home/jwolgast (p3k) <proddb> echo ${LOGNAME} | grep -q [A-Z]
/home/jwolgast (p3k) <proddb> echo $?
0
/home/jwolgast (p3k) <proddb> echo ${LOGNAME} | grep -q [a-z]
/home/jwolgast (p3k) <proddb> echo $?
0
/home/jwolgast (p3k) <proddb>
WTH? Why am I not getting a 1 return from echo ${LOGNAME} | grep -q [A-Z]? We even tried puting single quotes around the grep chars with the same results... I'm baffled, how can this not be working? It isn't pointing to anywhere funny and I don't have an alias that is forcing a -i or anything:
/home/jwolgast (p3k) <proddb> which grep
/usr/bin/grep
/home/jwolgast (p3k) <proddb> alias | grep grep
ld='ll | grep '\''/'\'
o='ps -ef | grep [o]racle'
psg='ps -ef | grep'
psq='ps -ef | grep quick'
/home/jwolgast (p3k) <proddb>
Any ideas??? TIA!!!
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2012 05:42 PM - edited тАО04-13-2012 06:56 PM
тАО04-13-2012 05:42 PM - edited тАО04-13-2012 06:56 PM
Re: strange grep behavior... (evil locales and ranges)
>grep is not always returning the same
Are you using the American Nerd (C) locale? If not, you can't trust things.
>We even tried putting single quotes around the grep chars
(That's always a good idea. Especially if you have a single char file in your directory.)
>how can this not be working?
You are depending on American Nerd concepts and you should set LANG=C.
This script will find ALL bad locales where your script will fail:
# looks for locales where upper == lower
for loc in $(locale -a); do
echo abc | LANG=$loc grep -q "[A-Z]" # sometimes works
if [ $? -eq 0 ]; then
echo "$loc: BAD"
else
echo "$loc: good"
fi
echo abc | LANG=$loc grep -q "[[:upper:]]" # works
if [ $? -eq 0 ]; then
echo "$loc [:upper:]: BAD"
else
: echo "$loc [:upper:]: good"
fi
done
You can be locale neutral by using a bigger hammer, character classes: "[[:upper:]]"
Or using just: LC_COLLATE=C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2012 05:53 PM
тАО04-13-2012 05:53 PM
Re: strange grep behavior...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2012 06:55 PM
тАО04-13-2012 06:55 PM
Re: strange grep behavior... (quoting)
>Without quotation, you could be looking at the files in the current working directory.
Yes but this will cause the opposite problem. You'll not be matching, when you think you should. (Unless you are using -v for non-matching logic.)
I.e. For a case of file "Y", you'll only match IDs that have "Y", not all upper case letters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2012 07:34 AM
тАО04-14-2012 07:34 AM
Re: strange grep behavior... (quoting)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2012 10:31 AM
тАО04-14-2012 10:31 AM
Re: strange grep behavior... (quoting)
>Perhaps. Or, perhaps not.
You don't believe Jenni when she said it still failed after quoting? ;-)
>including spurious matching, even without an exotic locale.
Yes, I forgot about the multiple file match case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-14-2012 12:30 PM
тАО04-14-2012 12:30 PM