- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- warning in a KSH script , which uses for HP-UX/LIN...
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
тАО03-14-2011 12:48 AM
тАО03-14-2011 12:48 AM
i am working mainly with KSH/HP-UX (11.31/ KSH Version ksh-88). but i have extend a KSH script for Linux (SLES 10 / KSH Version ksh-93t).
i check my scripts for warnings,errors with "ksh -n <script>"
for following statement i get warnings for Linux?
is HP-UX KSH or LINUX KSH right ?
i want to check , if a environment variable has only digit(s) :
Linux warning:
warning: line 121: $ not preceded by \
statement:
echo "${CHECK_DIGIT}" |grep -q "^[0-9]*$"
if [ "$?" != "0" ]
then
echo "${CHECK_DIGIT} must be a numeric-integer value"
exit 2
fi
Solved! Go to Solution.
- Tags:
- ksh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2011 02:36 AM
тАО03-14-2011 02:36 AM
SolutionI guess the warning comes from this:
> echo "${CHECK_DIGIT}" | grep -q "^[0-9]*$"
In this, it would be the last $ sign at the end of search expression of the grep command: when seeing an unescaped $ inside double quotes, the shell expects to see a variable expansion of some sort. But since $" is not a valid variable expansion, the shell figures you meant a literal dollar sign, and the double quote is the end quote for the search expression.
If you don't need to have any variables expanded inside grep's search expression, and the search expression includes characters with a special meaning to the shell (like "!" or "$"), then you might want to use single quotes instead of double quotes.
echo "${CHECK_DIGIT}" | grep -q '^[0-9]*$'
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2011 03:43 AM
тАО03-14-2011 03:43 AM
Re: warning in a KSH script , which uses for HP-UX/LINUX
thank you very much, you fix my problem. and i learned more about KSH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-14-2011 03:51 AM
тАО03-14-2011 03:51 AM
Re: warning in a KSH script , which uses for HP-UX/LINUX
As MK said, you typically use single quotes around grep/sed patterns that don't contain variables. Especially if they contain backslash.
>if [ "$?" != "0" ]
You should do a numeric compare on the exit status:
if [ $? -ne 0 ]; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-24-2011 11:58 PM
тАО03-24-2011 11:58 PM
Re: warning in a KSH script , which uses for HP-UX/LINUX
i wrote, i check my scripts for warnings,errors with "ksh -n <script>"
i changed my shell script, but how i change this warning ?
example statement:
teststring="aaa"
echo "aaa " | grep -e "${teststring} *$"
This is Linux warning:
warning: line 1: $ not preceded by \
i can not change " to ' in this case ?!?
is "ksh -n" a good way to check script for HP-UX, LINUX for the right syntax?
HP-UX doesn't show a warning !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2011 04:24 AM
тАО03-25-2011 04:24 AM
Re: warning in a KSH script , which uses for HP-UX/LINUX
> i changed my shell script, but how i change this warning ?
You can't, unless, perhaps, you managed your own, local message catalog. Welcome to the subtle differences between GNU, HP-UX and the other Unixes. Try AIX sometime. Its messages are even more different and contain "standard" message numbers meaningful only to AIX.
You don't want to concern yourself with the exact error/warning message text but rather the return code. Return codes should be consistent among the various UNIX and LINUX implementations. One similar example is with the 'ftpd' daemon where you are warned by the documentation not to rely on the exact text of the message, but rather examine the three-digit response code.
> is "ksh -n" a good way to check script for HP-UX, LINUX for the right syntax?
This checks for *errors* not warnings. Of course, syntactically error free code still doesn't necessarily execute without warnings or unforeseen consequences :-)
Remember that the shell is *interpreted* code, and thus to some extent only until a piece is interpreted are all the states relative to the data known.
I do find, that the GNU tools are far richer than the standard HP-UX (or AIX, etc.) ones, though .
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2011 03:42 PM
тАО03-25-2011 03:42 PM
Re: warning in a KSH script , which uses for HP-UX/LINUX
You can simply add that "\" before the "$".
>I can not change " to ' in this case?!?
You can but that will stutter your quotes and make it less readable:
...| grep -e "${teststring}"' *$'