LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-02-2009, 12:23 AM   #1
bertlacy
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Rep: Reputation: 0
Help with bash script...


Hey Guys,

I just need a lil help with some logic for a bash script that I am working on...

What I would like is for someone to post the logic I need for the following situation: I need the script to check to see if a directory is empty or not. If the directory is empty I want the script to exit, if not, I want it to continue further operations.

I know how to get it to work if I was looking for a certain/static file name but the directory will always have a different file name(s).

Thanks!
 
Old 07-02-2009, 01:06 AM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 69
Well, you'll probably need to pass the name of your directory as a variable then?
Something like this?

Code:
#!/bin/bash

if [ -d $1 -a -z "$(ls $1)" ]; then echo "empty"
else  echo "nope"
fi
Call this script something like scrypt.sh, make it executable and call it with the directory name, like this

./scrypt.sh testdir
 
Old 07-02-2009, 01:14 AM   #3
bertlacy
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks! I will try this out and get back to you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
[SOLVED] bash : getopts problem in bash script. angel115 Programming 2 03-02-2009 10:53 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
Bash script to create bash script jag7720 Programming 10 09-10-2007 07:01 PM
[bash] having trouble debugging this bash script. jons Programming 4 02-08-2007 06:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration