bad if test


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bad if test
# 1  
Old 07-19-2005
Data bad if test

Smilie

Bad if test:

if [ -f filename]

returns an error
I have changed filename to
"filename"s su
"$filename"
'filename''
'$filename''
"./filename"
"./$filename"

error is usually [ -f: command not found]
why cant I test the filename?

Thanks
# 2  
Old 07-19-2005
if [ -f filename] ; then echo file exist ; fi
if [ -f filename] ; then echo exist ; else echo " don't exist " ; fi
# 3  
Old 07-19-2005
I often use the double [[ ]] to get the ksh internal tests.
if [[ -f $File ]]
then
print "yes"
else
print "no"
fi

You could use -L to test links, or -n just to see if $File is set.
a short notation is
[[ -f $File ]] && print "yes" || print "no"

Als nice is:

[[ ! -f $File ]] && print "no file found" && return 1
(abort script, returns with non-zero exit code)
# 4  
Old 07-22-2005
PHP

Can you paste the script part where in you are using test.
# 5  
Old 07-22-2005
Spaces are significant when using test command ...

if [ -f "$filename" ]
then
...
fi

Note the space between filename and ]
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Prefixing test case methods with letter 'test'

Hi, I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Discussion started by: royalibrahim
5 Replies

2. Shell Programming and Scripting

Why I get bad bad substitution when using eval?

Why I get bad replace when using eval? $ map0=( "0" "0000" "0") $ i=0 $ eval echo \${map$i} 0000 $ a=`eval echo \${map$i}` !!!error happens!!! bash: ${map$i}: bad substitution How to resolve it ? Thanks! (5 Replies)
Discussion started by: 915086731
5 Replies

3. 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

4. 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

5. Shell Programming and Scripting

Bad day !! test condition failed --need a one liner to do --help

Hi all this is simple but bad day for me nothing work out .. Problem is that I wan to check the argument passed to my script and accordignly exit or setup ENV variable I have a script name src_cpcp_preproc.sh i want to pass 2 argumet from command line argumet and check it in the script... (13 Replies)
Discussion started by: jambesh
13 Replies

6. Shell Programming and Scripting

How can you Test for bad number

Anyone know the code to test for bad numbers? For example in ksh... Want the user to input an integer, but they input characters. read number while (number = letter) read number //until valid number is inputted thx for any help!! :confused: (3 Replies)
Discussion started by: gsxpower
3 Replies
Login or Register to Ask a Question