Help troubleshooting looped if statement..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help troubleshooting looped if statement..
# 1  
Old 07-19-2011
Help troubleshooting looped if statement..

Greetings all. I am trying to use the following code:
Code:
#!/bin/bash
geoDirs=("/logsync/GEO/DBS" "/logsync/GEO/NS")

for i in "${geoDirs[@]}"
do
        if[ "$(ls -A $i)" ]
                then
                        echo "Test"
        fi
done

Doing this returns the following error:
Code:
./test.sh: line 8: syntax error near unexpected token 'then'
./test.sh: line 8: '                        then'

Can anyone help with the syntax? I can't seem to find what I'm doing wrong unless it has to do with the whitespace. Your advice is appreciated.
Thanks!
# 2  
Old 07-19-2011
you need to add a space after "if"

#!/bin/bash
geoDirs=("/logsync/GEO/DBS" "/logsync/GEO/NS")

for i in "${geoDirs[@]}"
do
if [ "$(ls -A $i)" ]
then
echo "Test"
fi
done
# 3  
Old 07-19-2011
Now it works, thank you for your help!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Troubleshooting whiptail

Here is a code snippet using whiptail , it fails to complete giving me long list of options available for whiptail . That is great, but how do I determine which of the current opinions is wrong? I did tried inserting comment (#) into options and it just did not work. Deleting the option... (9 Replies)
Discussion started by: annacreek
9 Replies

2. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

3. AIX

iSCSI troubleshooting

I have an Equallogic SAN that I connect to from AIX (as well as Windows) I had configured the connection and created the volumes and filesystems and all was working great. Then one day, no communication between the SAN and the AIX (I can ping though) Anything I do on the AIX box at this time... (2 Replies)
Discussion started by: oldmanjoe
2 Replies

4. AIX

How to Troubleshooting IO in AIX 6.xx

I am running Oracle databases and recently have been facing slow IO response. I know in 11g one can run calibrate_IO from within DB and it would have given me some data for IO, but DB is 10g. Is there any tool available which can give me max MBPS, max IO requests per second system can handle and... (1 Reply)
Discussion started by: clifford
1 Replies

5. Solaris

help troubleshooting

Hi. I have a Solaris 10 server that's taking about 20secs to respond to telnet or ftp commands. Has anyone ever seen something like that? Can you tell me where to start troubleshooting please? I logged in and did a prtstat, but nothing is jumping out as an issue. (8 Replies)
Discussion started by: bbbngowc
8 Replies

6. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

7. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

8. UNIX for Dummies Questions & Answers

tftp troubleshooting

Hi I am trying to do a network install of Solaris 10 08_07 onto a Sunfire T2000. I have configured all my network-boot-arguments on the client server (named sundb1). I have installed my image of Solaris on my install server (sun1). But when I try to install using # boot net -s I get the... (0 Replies)
Discussion started by: Bobby76
0 Replies

9. Shell Programming and Scripting

Troubleshooting Script

I am fairly new to Unix (Sun OS) scripting with Ksh, and I could use a little help troubleshooting my script. When I run it, I get the error "if unexpected" on the function setYear. If I comment out the setYear function, I get the error "for unexpected" on the function sendEmails. This leads me... (8 Replies)
Discussion started by: mharley
8 Replies

10. UNIX for Advanced & Expert Users

Networking troubleshooting

How can i tell how long my network cards have been connected to the network for. (1 Reply)
Discussion started by: manwithaphone
1 Replies
Login or Register to Ask a Question