-a test in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting -a test in shell script
# 1  
Old 02-25-2010
-a test in shell script

I need clarification in -a test.

If say, in test -a left expression is not present but the right expression is present, do the shell will consider the left expression true and evaluate the right expression?

For example:
Code:
if [[ -a ${file} ]]
      then
      rm -f ${file}
fi

Is this test condition is true?

Help appreciated!! Thanks

Last edited by Scott; 02-25-2010 at 09:19 AM..
# 2  
Old 02-25-2010
Quote:
An omitted expression defaults to FALSE.

cheers,
Devaraj Takhellambam
# 3  
Old 02-25-2010
Thanks for fast response. But if omitted expression is always false then the test I have written is always remains false!! Which I supposed is not correct..
# 4  
Old 02-25-2010
Youtr test condition is true.

If the file exists then the test will be executed
# 5  
Old 02-25-2010
I am not sure what you are trying to achieve here. Read
Quote:
man test
cheers,
Devaraj Takhellambam
# 6  
Old 02-25-2010
Your code is perfect , -a is used to check for the file existence and return true
if the file exists otherwise false.
# 7  
Old 02-25-2010
Further to abubacker who is 100% correct.

The test within double square brackets [[...]] are evaluated according to the syntax for Conditional Expressions. This is described in the man pages for your shell. In that context the "-a" means "True if file exists".

Tests within single square brackets [..] are evaluated according to the rules for the "test" command. In that context "-a" means AND.

There is much overlap between the syntax for Conditional Expressions and "test" but they are not interchangeable.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell Script to test telnet connection using port

Hello, I need to test telnet connections using port number for few hosts. Could you please help me? Thanks !! (1 Reply)
Discussion started by: skhichi
1 Replies

2. Shell Programming and Scripting

Test shell script (PROBLEM)

Dears , kindly I wanna do test for one KSH script to know how is it working , the problem that I'm facing is whenever put "sh -x ./my_script.sh" the output seems very long & although I tried to to redirect it to files as it shown , but it failed :eek: :- sh -x ./my_script.sh >... (2 Replies)
Discussion started by: arm
2 Replies

3. UNIX for Dummies Questions & Answers

Test: argument expected error in shell script

Hi, I am trying to write a small script that validates if there exist files that start with a pattern in a given directory. Below is the piece of my script: #!/usr/bin/ksh BTFDIR=/opt/ships/temp if then echo 'found' else echo 'not found' fi When I run this... (2 Replies)
Discussion started by: snvniranjanrao
2 Replies

4. Shell Programming and Scripting

Help with connectivity test using shell script

I want to test connectivity between different servers with my server using information as IP and port only. I have Name,IP List and port in one file. Please help how i can test connectivity is successful or not? File format will be: Name1,127.0.0.1,80 Name2,127.0.0.2,8080 Output could be ... (1 Reply)
Discussion started by: poweroflinux
1 Replies

5. UNIX for Dummies Questions & Answers

How do i tell my bash shell script to test the output of a command against something

How do i tell my bash shell script to test the output of the command i'm using?? I want this script to look for lines not equal to 1 then let me know.. $ cat blah ; echo ---- ; cat blah.sh 1 fe 1 fi 1 fo 0 fum 1 blahda 1 blah 0 blahh 1 bla 1 bl 1 blahhh ---- #!/bin/bash while... (1 Reply)
Discussion started by: phpfreak
1 Replies

6. Shell Programming and Scripting

test script to identify SHELL

I am new to BASH and writing a small script to identify the SHELL . #!/bin/bash BASH='/bin/bash' KSH='/bin/ksh' if then echo "it's Bash" else echo "it's not Bash" fi $ bash -x a.sh + BASH=/bin/bash + KSH=/bin/ksh + '' a.sh: line 4: where am I missing . PLease advice . (10 Replies)
Discussion started by: talashil
10 Replies

7. Shell Programming and Scripting

Test for shell interpreter at beginning of script

What would be the best way or method to determine or test for the shell interpreter at the beginning of a script in the event one shell is not available? If I use the following: #!/bin/bash and /bin/bash is not available, then use I'd like to use /bin/ksh if it is available. #!/bin/ksh (8 Replies)
Discussion started by: nck
8 Replies

8. Shell Programming and Scripting

How to Create a shell script to test the telnet connection status

Hi friends, I'm newbie to shell script. I wanted to create a shell script which able to write a result for all the telnet connection status. For example, from this machine I want to test the telnet connection (total 100+ servers) with this machine. Any idea how to write this shell script?... (16 Replies)
Discussion started by: yhcheong
16 Replies

9. Shell Programming and Scripting

Test File Reading & Validation using Shell script

Please help develop script for below requirement -------Sample file------------------------------- HSVSHOSTRECON 20090115011817BP DARMAR60064966247003504720000000000000000000066626000000000000133000003D003463001332 ... (14 Replies)
Discussion started by: niraj_bhatt
14 Replies

10. Shell Programming and Scripting

need help with test condition in shell script

I'm new to scripting and I need help with a bourn shell script. What i'm trying to do is a test condition where "if the time is within 2 hours, it's true" and so on. The time is in the following format DATE=`/bin/date +"%Y%m%d%H%S"` for example, 20060907152000. So, what the script first... (9 Replies)
Discussion started by: pieman8080
9 Replies
Login or Register to Ask a Question