Jan 18, 2005 #1 jouell MIS Nov 19, 2002 304 US How do I do: if [command fails];then something fi I am missing the syntax in the man page I think. I'd like to not use the command || command2 syntax... Thanks!
How do I do: if [command fails];then something fi I am missing the syntax in the man page I think. I'd like to not use the command || command2 syntax... Thanks!
Jan 18, 2005 #2 PHV MIS Nov 8, 2002 53,708 FR Either: [ command fails ] || { something } Or: if [command fails]; then :; else something fi Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244 Upvote 0 Downvote
Either: [ command fails ] || { something } Or: if [command fails]; then :; else something fi Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
Jan 18, 2005 Thread starter #3 jouell MIS Nov 19, 2002 304 US So I would do: [ grep -i word $variable ] || { echo word not in $variable } if I understand correctly? Upvote 0 Downvote
So I would do: [ grep -i word $variable ] || { echo word not in $variable } if I understand correctly?
Jan 18, 2005 #4 PHV MIS Nov 8, 2002 53,708 FR Provided $variable expand to a valid filename: grep -i word $variable || echo word not in $variable Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244 Upvote 0 Downvote
Provided $variable expand to a valid filename: grep -i word $variable || echo word not in $variable Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
Jan 18, 2005 #5 vgersh99 Programmer Jul 27, 2000 2,146 US use quotes for your filename as it might contain blanks/newLines etc... grep -i word "$variable" || echo word not in $variable vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+ Upvote 0 Downvote
use quotes for your filename as it might contain blanks/newLines etc... grep -i word "$variable" || echo word not in $variable vlad +----------------------------+ | #include<disclaimer.h> | +----------------------------+
Jan 18, 2005 #6 PHV MIS Nov 8, 2002 53,708 FR If you search if variable (as text string) contains word: case $variable in *word*) :;; *) echo word not in $variable;; esac Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244 Upvote 0 Downvote
If you search if variable (as text string) contains word: case $variable in *word*) :;; *) echo word not in $variable;; esac Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
Jan 18, 2005 #8 chipperMDW Programmer Mar 24, 2002 1,268 US If you're using Bash, you can write: Code: if ! command; then do something fi That's probably a Bash-specific extension, though. For example, Code: if ! false; then echo cool fi outputs [tt]cool[/tt]. Note that [tt]if[/tt] takes any command as an argument. The [tt][[/tt] command is simply the most commonly used one. Upvote 0 Downvote
If you're using Bash, you can write: Code: if ! command; then do something fi That's probably a Bash-specific extension, though. For example, Code: if ! false; then echo cool fi outputs [tt]cool[/tt]. Note that [tt]if[/tt] takes any command as an argument. The [tt][[/tt] command is simply the most commonly used one.
Jan 19, 2005 Thread starter #9 jouell MIS Nov 19, 2002 304 US Thanks all I like this the best: from cdlvj (MIS) Jan 18, 2005 if [ $? != 0 ] ---------------------------------- So I will do if [ ! -n $EXPORT_DIR ];then echo EXPORT_DIR is $EXPORT_DIR - not set - Abort! | tee -a $LOGFILE exit 1; fi if [ ! -d $EXPORT_DIR ];then echo EXPORT_DIR is $EXPORT_DIR - invalid directory - Abort! | tee -a $LOGFILE exit 1; fi if [ $EXPORT_DIR = "/" ];then echo EXPORT_DIR is / - Abort! | tee -a $LOGFILE exit 1; fi grep -i exports $EXPORT_DIR if [ $? != 0 ];then echo exports not found in $EXPORT_DIR - Abort! | tee -a $LOGFILE exit 1; fi As four checks before running my rm statement: find $EXPORT_DIR -ctime +$DAYS_OLD -name \*.gz -exec rm -e {} \; 2>> $LOGFILE -john Upvote 0 Downvote
Thanks all I like this the best: from cdlvj (MIS) Jan 18, 2005 if [ $? != 0 ] ---------------------------------- So I will do if [ ! -n $EXPORT_DIR ];then echo EXPORT_DIR is $EXPORT_DIR - not set - Abort! | tee -a $LOGFILE exit 1; fi if [ ! -d $EXPORT_DIR ];then echo EXPORT_DIR is $EXPORT_DIR - invalid directory - Abort! | tee -a $LOGFILE exit 1; fi if [ $EXPORT_DIR = "/" ];then echo EXPORT_DIR is / - Abort! | tee -a $LOGFILE exit 1; fi grep -i exports $EXPORT_DIR if [ $? != 0 ];then echo exports not found in $EXPORT_DIR - Abort! | tee -a $LOGFILE exit 1; fi As four checks before running my rm statement: find $EXPORT_DIR -ctime +$DAYS_OLD -name \*.gz -exec rm -e {} \; 2>> $LOGFILE -john