Making a Directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making a Directory
# 1  
Old 03-22-2005
Making a Directory

Hi everyone,

Im trying to make a new directory based on a name given in a file called directory_file which contains the following content:

garbage gargbage
Directory: running
more garbage gargbage
more garbage gargbage
more garbage gargbage

So basically i have a shell script that makes a 1 level deeper directory called "running" than the shell script itself. If that directory already exists i need to delete that directory and wipe any files that it may contain and then make the same directory again.

my script so far is as follows:

cat directory_file while read LINE
do

if [ "`echo ${LINE} |grep 'Directory:'$`" != "" ] ; then
dir=`echo ${LINE} | cut -d ":"`
`mkdir $dir`
continue
fi

done



It dosent seem to make the directory and im not sure on how to check if a directory exists and if so delete it before making another. If someone knows whats wrong with my solution please let me know..im looking to fix my solution rather than designing a whole new one.

cheers
# 2  
Old 03-22-2005
Try with this script as,

Code:
while read line; do
  echo $line | grep -q '^Directory'
  if [[ $? -eq 0 ]]
  then
    mkdir $(echo $line | cut -d ':' -f2)
  fi
done < directory_file

It will work.

HTH.
# 3  
Old 03-22-2005
thanks for ur help,

one question: will it check if the directory exists and if so delete it and all its content before making the same directory?

thanks
# 4  
Old 03-22-2005
Quote:
Originally Posted by nbvcxzdz
thanks for ur help,

one question: will it check if the directory exists and if so delete it and all its content before making the same directory?

thanks
Try with this to delete the existing directory as,

Code:
while read line;do
echo $line | grep -q '^Directory'
if [[ $? -eq 0 ]]
then
   dir=$(echo $line | cut -d ':' -f2)
   [[ -d $dir ]] && rm -rf $dir
   mkdir $dir
fi
done < directory_file

HTH.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me making this script

This script is executed whenever a new vehicle is added to the cycle-motor park of campus. The script asks for the following information about the car and adds a new line to the vehicle file.txt: name (name of an animal, unique identifier), color, mark, model, type (e.g., electrical, manual),... (2 Replies)
Discussion started by: andre2222
2 Replies

2. AIX

Making Tar of directory and tar file is going to be placed

Quick question, is it possible to make a Tar of completely directory and placing the tar file in it (will this cause even the tar file to tarred ?) sample: /opt/freeware/bin/tar -cvf - /oracle | gzip > /oracle/backup.tgz will the tar file backup.tgz also include backup.tgz ? i tried... (5 Replies)
Discussion started by: filosophizer
5 Replies

3. Shell Programming and Scripting

I could use some help with making a script

I run a small instrument lab. We track our user's time on the instruments with a very manual process of 'last wtmp.1' then cut/paste data into spreadsheets. My boss makes the initial spreadsheets then I convert and format them for uploading into our billing software (COReS). Cores is looking for a... (8 Replies)
Discussion started by: jpontius
8 Replies

4. Shell Programming and Scripting

making find/sed to include directory names with spaces

how can i make find/sed to include directory names with spaces the command is like this for i in `find wp-content/themes -type f -print0 | xargs -0 grep -l -iE 'e'`;do sed -i -e 's/word1/word2/gI' "$i";done but it skips one directory names with spaces sed: can't read ./Nova: No such... (5 Replies)
Discussion started by: vanessafan99
5 Replies

5. UNIX for Advanced & Expert Users

Regarding help for making own OS

Dear Fellow, I want to make my own OS, Kindly suggest from where i should start. please help me out. (2 Replies)
Discussion started by: zaigham_tt
2 Replies

6. UNIX for Dummies Questions & Answers

Help making a library

I understand how to use vi and emacs but I have a project which entails building a library application like a phone directory or listing of dvd's. I am lost on where to start. any help would be appreciated. (3 Replies)
Discussion started by: gustave
3 Replies

7. Shell Programming and Scripting

making sure my string is [a-z] only

Hi there I am trying to figure out how I can validate my string to ensure that it is consists of only lower case alpha chrataters but for some reason whatever I do, it seems to come back with 'true' I have tried if " ]] ; then echo "yes its fine" else echo... (21 Replies)
Discussion started by: hcclnoodles
21 Replies

8. Shell Programming and Scripting

making script

hello experts cany any one help me i want to make one script which can rlogin to another machine . but it should not ask me username/password from me of another machine it should take the username and password from the script only. please help me out. regards, shary (2 Replies)
Discussion started by: shary
2 Replies

9. UNIX for Dummies Questions & Answers

Making the right choise

I need help on making right decision on witch unix based OS to choose from. What woud be the great for a beginner? :confused: (8 Replies)
Discussion started by: thunderfastfox
8 Replies
Login or Register to Ask a Question