Hi everyone, I am new to UNIX, here I have a if statement elevating two boolean conditions. I thought the output should be True because there are [true] + [true] in the statement. But it turns out to be False.
Can anyone explain to me how to properly use the boolean condition here? Thanks a lot!
Last edited by Scott; 07-30-2013 at 03:22 AM..
Reason: Code tags
There are utilities named true and false on UNIX and Linux systems, but you aren't using them in your if statement. If you wanted to use them, the if statement would be:
The if statement you had was using the test utility to evaluate whether or not "true" was <not an empty string> which evaluates to true and the second test utility invocation to evaluate whether or not NOT ("false" was <not an empty string>) which evaluates to false. Since both did not evaluate to true, the AND of the two tests evaluates to false and you executed the "else" branch of your if statement.
line 46: no: command not found
line 46: -d: command not found
but my code are different from what I typed above.
elif ! $recursive && -d $originalPath/$filename
then
echo ".................."
for the first condition, recursive takes on the boolean value, and the second condition is to check if the file exists in that directory.
Would you suggest a better approach?
First look at the test man page on your system (or the man page for the shell you're using and look at its description of its built-in test utility). With what you're testing here, you do want to use the test utility; with what you were doing in the first posting in this thread, you didn't want to use the test utility.
After looking at the man page, it should be obvious that the test utility takes two forms:
and
and some shell also provide other forms. But, these two ways of writing a test command produce exactly the same results; the 2nd form is much more common in shell scripts. Note that the expression must be separated from the test or the [ and ] by one or more spaces or tabs.
From the error messages you're getting, I will make the assumption that the shell variable recursive is expected to either have the value "no" or "yes". Assuming that is correct, you probably want an if statement similar to:
I picked up the value "no" for recursive from the errors you got. If my guess that "yes" is the other valid value, I would rewrite the elif clause to be:
to get rid of the double negative logic ("no" is not the value of recursive) because it is easier for humans to parse "yes" is the value of recursive.
I wish to check two conditions inside the if statement
Condition 1: The two file contents should be identical // using cmp command for this.
Condition 2: The two filenames should NOT be the same.
This is what i did in vain.
if ]; then
where entry1 and entry2 are
ls *.txt | while... (7 Replies)
I was trying to write multiple conditions inside the if statement but its not working.
export VAR_NM=abc.txt
export CURR_DT=20131011
export PREV_DT=20131012
if &&
then
echo "Yes"
else
echo "NO"
fi
It should return Yes but returning NO always.Appreciate any help. (3 Replies)
I am trying to test two conditions in a single if and getting syntax error on -a and &&
if ] ; then
echo "variable a equals to variable b"
else
echo "variable a not equal to variable b"
fi
in second attempt I used -a instead of &&, referring to other website, but not sure that... (1 Reply)
Hello,
I'm trying to put together a script that involves pulling data from a config file. I'm attempting to write an if statement to validate one of the pieces of data from the config file, but I think I'm fat fingering it somehow.
$config{VALUE} is being pulled from a config file but can only... (4 Replies)
is it possible to use multiple conditions in a CASE statement? And if so, what is the syntax? I'm trying to use one but can't seem to get it right. I want the statement to be
CASE $vendor OR $alias
condition 1) statements;
condition 2) statements;
etc.
esac
but I keep... (25 Replies)
I have a script that runs every 15 minutes in cron that builds a web page.
It runs at 15, 28, 45 and 58 minutes past the hour. (pretty much evry 15 mins).
Every 2 hours from 6:28 to 18:28 it sends out emails if it finds errors. I do not want it sending email every single time it runs, every 15... (5 Replies)
I have a script that runs on multiple servers. What I want to do is have the script do the following:
if $(hostname) is equal to server or server2
then
TO_DIR=go
else
TO_DIR=stop
fi
I have tried:
if
if ]
Server is hpux.
any ideas? (1 Reply)
I'm totally new with bash programming and I don't get it how to put two conditions in one if statement. My code looks like this:
h=`date +%k`
if && ]; then$h is 10 but I don't get into my if statement. What's wrong here? (5 Replies)
Actually i need to satisfy both the condition..
lik i'm lookin for two different files.. and if BOTH the files r not present then it should run the followin script.. For example
inputfile1=data/in/inputfile1.txt
inputfile2=data/in/inputfile2.txt
if
then
echo " "
echo... (6 Replies)
Hi,
I am trying to use && set up to match two conditions within ksh:
if &&
then
'''Do something
if
somehow, I keep getting error message telling me that ] is missing.
What's wrong with my code?
Thanks a lot for your help! (1 Reply)