LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 09: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, 10:02 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Throw it in a loop with a way to escape - check here - tldp.org/LDP/abs/html/loops.html
 
Old 05-26-2010, 10: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, 10:13 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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, 10: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-26-2010, 11:57 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

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


Reply



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 07: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 03:43 PM
Read and write to a co-process in bash Bambi535 Linux - Software 3 11-25-2008 12:58 PM
Bash script to read file and alter lines depending on create date ChristianHein Linux - General 13 08-04-2007 05:39 AM
How to create a bash script to automatically disown a process. jon_k Linux - Software 5 06-19-2005 05:53 AM

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

All times are GMT -5. The time now is 08:53 PM.

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
Open Source Consulting | Domain Registration