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
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)
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)
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)
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 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)
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)
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)
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)
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 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)
Discussion started by: mohtashims
7 Replies
LEARN ABOUT DEBIAN
plan9-test
TEST(1) General Commands Manual TEST(1)NAME
test - set status according to condition
SYNOPSIS
test expr
DESCRIPTION
Test evaluates the expression expr. If the value is true the exit status is null; otherwise the exit status is non-null. If there are no
arguments the exit status is non-null.
The following primitives are used to construct expr.
-r file True if the file exists (is accessible) and is readable.
-w file True if the file exists and is writable.
-x file True if the file exists and has execute permission.
-e file True if the file exists.
-f file True if the file exists and is a plain file.
-d file True if the file exists and is a directory.
-s file True if the file exists and has a size greater than zero.
-t fildes True if the open file whose file descriptor number is fildes (1 by default) is the same file as /dev/cons.
-A file True if the file exists and is append-only.
-L file True if the file exists and is exclusive-use.
-Tfile True if the file exists and is temporary.
s1 = s2 True if the strings s1 and s2 are identical.
s1 != s2 True if the strings s1 and s2 are not identical.
s1 True if s1 is not the null string. (Deprecated.)
-n s1 True if the length of string s1 is non-zero.
-z s1 True if the length of string s1 is zero.
n1 -eq n2 True if the integers n1 and n2 are arithmetically equal. Any of the comparisons -ne, -gt, -ge, -lt, or -le may be used in place
of -eq. The (nonstandard) construct -l string, meaning the length of string, may be used in place of an integer.
a -nt b True if file a is newer than (modified after) file b.
a -ot b True if file a is older than (modified before) file b.
f -older t True if file f is older than (modified before) time t. If t is a integer followed by the letters y(years), M(months), d(days),
h(hours), m(minutes), or s(seconds), it represents current time minus the specified time. If there is no letter, it represents
seconds since epoch. You can also concatenate mixed units. For example, 3d12h means three days and twelve hours ago.
These primaries may be combined with the following operators:
! unary negation operator
-o binary or operator
-a binary and operator; higher precedence than -o
( expr ) parentheses for grouping.
The primitives -b, -u, -g, and -s return false; they are recognized for compatibility with POSIX.
Notice that all the operators and flags are separate arguments to test. Notice also that parentheses and equal signs are meaningful to rc
and must be enclosed in quotes.
EXAMPLES
Test is a dubious way to check for specific character strings: it uses a process to do what an rc(1) match or switch statement can do. The
first example is not only inefficient but wrong, because test understands the purported string "-c" as an option.
if (test $1 '=' "-c") echo OK # wrong!
A better way is
if (~ $1 -c) echo OK
Test whether is in the current directory.
test -f abc -o -d abc
SOURCE
/src/cmd/test.c
SEE ALSO rc(1)TEST(1)