LinuxQuestions.org
Visit Jeremy's Blog.
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 11-15-2010, 04:37 PM   #1
navie
LQ Newbie
 
Registered: Nov 2010
Posts: 6

Rep: Reputation: 0
Shell scripting


I have an assignment "Write a Bash script that removes all zero length ordinary files in the current directory. Do appropriate error checking.", and I know for that I have to use an if statement with -s "$1" condition. The only thing I am confused about is that do I have to go through all the files in that directory? and lets say the script file that I created is in Script directory and it has three files. This script will go through all the three files and check its size? If the answer is yes then how am I supposed to pass the three files as an argument to the script. Any suggestions?
 
Old 11-15-2010, 04:43 PM   #2
tuxtutorials
Member
 
Registered: Dec 2008
Location: New York
Distribution: RedHat, Solaris
Posts: 68

Rep: Reputation: 16
I would start reading up on for loops, this looks like what you would need.
 
Old 11-15-2010, 05:16 PM   #3
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware, Mint
Posts: 1,252

Rep: Reputation: 205Reputation: 205Reputation: 205
You don't need complicated loops. It should be enough to use one liner with find command using some sophisticated switches. A few examples of such commands you'll find here. Analyse them and review man find.
 
Old 11-15-2010, 07:03 PM   #4
navie
LQ Newbie
 
Registered: Nov 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Yeah I think I need to use do-while or while. What I am thinking is that I need to pass the files as an argument one at a time and the script will check the size. If the size is zero it will remove the file and will loop back and check another and so on. How can I pass them(files) to the script I don't understand that.
 
Old 11-15-2010, 10:46 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Or both find and a loop with the loop iterating once for each file given by find. As for the somewhat artificial requirement to use a -s $1 test, that could be satisfied by calling a function from the loop; it would be the function's $1, not the script's initial $1.
 
Old 11-15-2010, 11:17 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Good bash guides:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
  


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
LXer: Terminal functions for shell scripting with Shell Curses LXer Syndicated Linux News 0 03-27-2008 12:50 AM
SHELL scripting/ shell functions mayaabboud Linux - Newbie 6 12-26-2007 09:18 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM


All times are GMT -5. The time now is 06:45 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