- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- If sentence ..
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-14-2005 02:57 AM
12-14-2005 02:57 AM
how cay i use if to indicate a sentence:
if $a (is bigger than) $b
then ...
"is bigger than" how can i indicate it in if sentence? is like -ge? is like -aq? what is, i don't remember it ...!!!
Thanks, Manuales.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 03:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 03:02 AM
12-14-2005 03:02 AM
Re: If sentence ..
if [ $a -gt $b ]
then
...
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 03:02 AM
12-14-2005 03:02 AM
Re: If sentence ..
if you type man test it will show some useful syntax.
- Tags:
- Test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 03:02 AM
12-14-2005 03:02 AM
Re: If sentence ..
if test $a ...... Bb
whad do you put in space "...." ?
Tnanks, Manuales.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 03:04 AM
12-14-2005 03:04 AM
Re: If sentence ..
for strings:
"=" equal
"!=" not equal
for numbers:
"-eq" equal
"-ne" not equal
"-gt" greater than
"-lt" less than
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 03:07 AM
12-14-2005 03:07 AM
Re: If sentence ..
I assume that you want the Posix (or 'ksh') shell syntax.
If so, see the man pages for 'test' and the man pages for 'sh-posix'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 03:10 AM
12-14-2005 03:10 AM
Re: If sentence ..
#!/usr/bin/ksh
a="A"
b="B"
if [[ "$a" > "$b" ]]
then
echo a greater than b
else
echo a not greater than b
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 03:14 AM
12-14-2005 03:14 AM
Re: If sentence ..
A review of "man test" and "man ksh" will explain the differences.
For instance-
if [ ab = a* ]... is false since it is a string compare, whereas
if [[ ab = a* ]]... is true since it is doing a pattern match.
read the "man" pages for the details...
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 06:03 AM
12-14-2005 06:03 AM
Re: If sentence ..
why do i have next error?
serverunix:girl1 279> prueba.csh
if: Expression syntax.
my script is:
if ($bb = 1)
then
echo "hola"
else
echo "adios"
eif
why is the problem??
Thanks, Manuales.
- Tags:
- csh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 06:15 AM
12-14-2005 06:15 AM
Re: If sentence ..
if ($bb = 1) then
echo "hola"
else
echo "adios"
endif
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 06:17 AM
12-14-2005 06:17 AM
Re: If sentence ..
Your script should be:
if ( $bb == 1 ) then
echo "hola"
else
echo "adios"
endif
Note the differences.
1st line -- You needs space between the open and close parentheses and the expressions. Also you needed a '==' (2 equal signs together) and the 'then' needs to be on the first line.
The last line of the script has to be 'endif'.
# man csh
will give you a LOT of info on the C-shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 06:28 AM
12-14-2005 06:28 AM
Re: If sentence ..
i've worked with ksh ..
do you know if with csh you can make functiions llike ksh? it means, with ksh there is a variable specially to redirect a path where there will be functions .. do you kwno if this exists to csh?
Thanks, Manuales.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 06:35 AM
12-14-2005 06:35 AM
Re: If sentence ..
The 'csh' shell is far inferior to the Posix ('usr/bin/sh'), 'ksh', and 'bash' shells.
See here, for one discussion of why *not* to use 'csh':
http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
Beyond, that, on HP-UX, for the 'root' account, in '/etc/passwd', NEVER specify any shell other than '/sbin/sh'. To do so will render your server unusable.
The Posix shell lives in '/sbin/sh' as a staticly-linked binary. As such, everything it needs to run is available in single-user mode (when '/usr' isn't mounted). The Posix shell in '/usr/bin/sh' is for general users and uses dynamically linked libraries in '/usr'. Non-root users should specify this shell in preference to '/sbin/sh'.
Regards!
...JRF...
- Tags:
- scummy C shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 06:47 AM
12-14-2005 06:47 AM
Re: If sentence ..
I try to avoid it if at all possible. I much prefer the POSIX shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 08:15 AM
12-14-2005 08:15 AM
Re: If sentence ..
i have a problem,
running script manually is ok. but if i run it from cron i have an error:
/home/scripts/test.sh[21]: Syntax error at line 56 : `else' is
not matched.
why?
my script is:
#!/usr/bin/csh
set p_monit=/home/scripts/MONITORING
#--->12132005 This is to take correct name in script
cd /interface/Towers/exe/backup
set aa=`ls -l | grep earn | awk '{ print $NF }'`
set bb=`echo $aa | wc -w`
if ($bb == 1) then
mv $aa db.opo
chmod 775 db.opo
else
set mensaje=`cat $p_monit/mail_messages.txt | grep 01 | cut -d":" -f2`
echo $mensaje | mailx -s "01 ORANGE ALERT to Mexico" me@patito.com.mx
endif
Thanks, Manuales.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 08:27 AM
12-14-2005 08:27 AM
Re: If sentence ..
The 'cron' environment is quite sparse, containing:
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
That is, *any* variables that are usually in your profile or login file are *not* available unless you specifically include them.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 08:31 AM
12-14-2005 08:31 AM
Re: If sentence ..
/home/scripts/test.sh[21]: Syntax error at line 21 : `if' is not matched
Thanks, Manuales.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 08:32 AM
12-14-2005 08:32 AM
Re: If sentence ..
put su - user before the script in your crontab
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 08:34 AM
12-14-2005 08:34 AM
Re: If sentence ..
put su - USERNAME in front the script in your crontab
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 08:34 AM
12-14-2005 08:34 AM
Re: If sentence ..
(csh /path/to/yourscript > /tmp/yourscript.cronlog 2>&1 )
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 08:35 AM
12-14-2005 08:35 AM
Re: If sentence ..
/home/scripts/test.sh[21]: Syntax error at line 21 : `if' is not matched
or another error:
if: Empty if.
Thanks, Manuales.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 08:44 AM
12-14-2005 08:44 AM
Re: If sentence ..
This is one of the reasons most of us avoid the 'csh'. 'cron' expects to process scripts with the Posix shell.
Wrap your 'csh' script thusly and then 'cron' it:
#!/usr/bin/sh
/path_to_your_csh_script
You can see this by doing this, assuming your 'csh' script is named "/tmp/manuales":
# sh /tmp/manuales
# csh /tmp/manuales
The first will syntax; the second will work.
Regards!
...JRF...
- Tags:
- cron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2005 08:47 AM
12-14-2005 08:47 AM
Re: If sentence ..
http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
And then change your script from csh to the posix shell - /usr/bin/sh
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2005 05:09 PM
12-30-2005 05:09 PM
Re: If sentence ..
if [[ -s /home/file1 ]]
then
....
fi
what is the meaning of "s"?
do you know any link speaks about parameters to if: -gt, -n, etc?
Thanks, Manuales.