if and test not working


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users if and test not working
# 1  
Old 06-19-2012
if and test not working

All,

I am getting error when run file check with test operator . Why is it showing the error

Code:
if [ test -r filename ]             
 then
 echo 'file found'
  fi

ksh: -r: unknown test operator


I know i can use the below code to test the file but why the above is not working

Code:
if test -r filename
 then
 echo 'filename found'
 fi

Thanks,
Arun
# 2  
Old 06-19-2012
test and [ are the same command, you cannot use both at the same time.
Code:
if [ -r filename ]             
then
  echo 'file found'
fi

# 3  
Old 06-20-2012
Quote:
Originally Posted by jlliagre
test and [ are the same command
...literally, I might add.

Code:
$ whereis [

[: /usr/bin/[

$

# 4  
Old 06-22-2012
Thanks for the explanation
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Test -e not working as expected (by me)

I ran into the following and still do not understand entirely the rationale behind this. If someone could explain why things are as they are I'd be thankful. The following was tested on AIX 7.1 with ksh88, but i suspect that to be ubiquitous. In an installation routine i had to create a set of... (6 Replies)
Discussion started by: bakunin
6 Replies

2. Shell Programming and Scripting

Test function not working

i am writing the following snippet and cannot figure out why the variable measType remains 0. it should be 1 I also tried "\#analog" and '\#analog' in the test statement and it still doesn't work. What is going on? bash$ measType=0 bash$ read line < 2iconfig.ini bash$ echo $line #analog... (4 Replies)
Discussion started by: oahmad
4 Replies

3. Shell Programming and Scripting

Use The Terminal To Test Arduino Is Working.

Hi all... (Apologies for any typos at all.) This is a step by step _script_ to check if your Arduino is talking to your Linux or Macbook Pro computer using the Terminal... It works on at least 3 Linux flavours and now the Macbook Pro... I hope you find it useful as a simple check for... (0 Replies)
Discussion started by: wisecracker
0 Replies

4. Shell Programming and Scripting

String == isn't working in [[-test

Hi. I'm new to this forum, my English perhaps is not so good, but here is my question: In bash you can use ] for tests, and how I understand it the variable names should be expanded automatically. So this should give "yes": xx=hello $ ] && echo yes || echo no no # not giving "yes" These two... (2 Replies)
Discussion started by: 244an
2 Replies

5. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

6. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

7. Solaris

How i test the UDP port is working?

Hi anybody know how to test out the UDP port working? cos UDP cannot use telnet to test... Sumemr (2 Replies)
Discussion started by: summerpeh
2 Replies

8. Shell Programming and Scripting

test command is not working

#!/bin/ksh size=3978132853 limit=100 if ;then echo exceeded limit fi This does not work though if i reduce 3978132853 to 397813285 it works any ideas and work around appreciated (SunOS 5.9 Generic_117171-02 sun4u sparc SUNW,Ultra-80 ) (2 Replies)
Discussion started by: zam
2 Replies
Login or Register to Ask a Question