LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-26-2010, 10:59 PM   #1
davisbase
LQ Newbie
 
Registered: May 2010
Posts: 3

Rep: Reputation: 0
Create BASH script to process multiple inputs on read


First post from a very new Linux user....I am trying to create a BASH script that will allow user to provide multiple directory names, Checks if the directory exists and if not create the directory. I am using the following code:
CreateFolder()
{
echo "Enter the name(s) of the folder you would like to create."
read directory
if [ -d $directory ]; then
echo "Directory $directory exists"
else
mkdir $directory
fi
}
which works fine as long as the user enters a single directory name. How can I modify this so it will process all directory names user enters on the read response?

Thanks for your help.
 
Old 05-26-2010, 11:02 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Throw it in a loop with a way to escape - check here - tldp.org/LDP/abs/html/loops.html
 
Old 05-26-2010, 11:05 PM   #3
davisbase
LQ Newbie
 
Registered: May 2010
Posts: 3

Original Poster
Rep: Reputation: 0
I understand that i need a loop but what is the output of the read statement that I should input into the loop?
 
Old 05-26-2010, 11:13 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Quote:
what is the output of the read statement that I should input into the loop?
You have lost me?? The same read you have now except ask for one at a time or you will need an internal loop as well if there are multiple.
 
Old 05-26-2010, 11:45 PM   #5
davisbase
LQ Newbie
 
Registered: May 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for the help. I took a closer look at for loops and figured out I should use for i in $directory loop.
 
Old 05-27-2010, 12:57 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Cool ... glad you got there. Please mark as SOLVED if you have your solution.
 
  


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
Can bash create a detached process? GN9500 Linux - Newbie 4 07-08-2012 08:28 PM
How do I make my BASH script yes/no user input query terminate with 3 invalid inputs? lupusarcanus Linux - Newbie 9 03-16-2010 04:43 PM
Read and write to a co-process in bash Bambi535 Linux - Software 3 11-25-2008 01:58 PM
Bash script to read file and alter lines depending on create date ChristianHein Linux - General 13 08-04-2007 06:39 AM
How to create a bash script to automatically disown a process. jon_k Linux - Software 5 06-19-2005 06:53 AM


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