- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- if - then statement does'nt work
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
тАО07-12-2010 08:04 PM
тАО07-12-2010 08:04 PM
#!/bin/sh
WK=`date +%W`
NWK=`expr $WK % 2`
if $NWK -eq "0"; then
WKS="week-1";
else
WKS="week-2";
fi
echo "today :" `date`
echo "#week :" $WK
echo "nweek :" $NWK $WKS
When I execute the result as follows:
./calcweek.sh[4]: 0: not found.
today : Tue Jul 13 10:58:35 TST 2010
#week : 28
nweek : 0 week-2
The question is
1. what means " 0: not found"
2. why if-then statement does'nt work? (if nweek=0 should "week-1")
Thanks very much for your willingness to help.
Regards,
Solved! Go to Solution.
- Tags:
- scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2010 08:29 PM
тАО07-12-2010 08:29 PM
Re: if - then statement does'nt work
As a command, "$NWK" ("0") is not very
useful. Perhaps something more like:
if test "$NWK" -eq 0 ; then
or:
if [ "$NWK" -eq 0 ]; then
man test
(Quoting "$NWK" avoids syntax errors if NWK
is empty. If "-eq" is a numeric test, then
quoting "0" may be more confusing than
helpful. Some of your semi-colons
("WKS=...;") seem to be unnecessary.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2010 08:50 PM
тАО07-12-2010 08:50 PM
Re: if - then statement does'nt work
#!/bin/sh
WK=`date +%W`
NWK=`expr $WK % 2`
if ["$NWK" -eq 0]; then
WKS="week-1"
else
WKS="week-2"
fi
echo "weeks:" $WK $NWK $WKS
The result is still same as previous:
./calcweek.sh[4]: [0: not found.
weeks: 28 0 week-2
I still expect your assistance.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2010 09:06 PM
тАО07-12-2010 09:06 PM
Solution> [...]
Perhaps you should try copy+paste. Or be
more careful. Sometimes, spaces can be
important.
> The result is still same as previous:
> [...]
No, it's not the same.
> ./calcweek.sh[4]: 0: not found.
> ./calcweek.sh[4]: [0: not found.
See the difference?
> man test
Also, to see how "if" works:
man sh
man sh-posix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2010 09:26 PM
тАО07-12-2010 09:26 PM
Re: if - then statement does'nt work
You are corect. Sametimes, spaces is very usefull. I was careless.
Thanks for your explanation.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2010 09:28 PM
тАО07-12-2010 09:28 PM