Results 1 to 2 of 2
I have created a script that finds a directory and subdirectories in my home directory and creates a copy of the directory structure in my home directory (i.e. just the ...
- 10-27-2010 #1Just Joined!
- Join Date
- Aug 2010
- Posts
- 9
mkdir in script not working
I have created a script that finds a directory and subdirectories in my home directory and creates a copy of the directory structure in my home directory (i.e. just the empty directories, no files). The script is adapted from the book Classic Shell Scripting, by Robbins and Beebe. For anyone who has the book the original script is at the bottom of pg 49.
This is my script:
I have turned on execution tracing to see what is produced and it all looks OK, viz.:Code:#!/bin/bash find /home/canopus/LearningPerl2/ -type d -print | sed 's;/home/canopus/LearningPerl2/;~/lt/;' | sed 's/^/"mkdir -p" /'
However, I find that the parent directory (lt) has not been created. If I type the first mkdir command shown above from the command line, it is created.Code:mkdir -p ~/lt/ mkdir -p ~/lt/chapter1 mkdir -p ~/lt/chapter2 mkdir -p ~/lt/chapter3
Anyone any idea why it doesn't work in the script but does from the command line.
Bash version is
Many thanksCode:$ bash --version GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc.
- 12-11-2010 #2
You haven't executed the code. Pipe the output to sh:
Code:find /home/canopus/LearningPerl2/ -type d -print | sed 's;/home/canopus/LearningPerl2/;~/lt/;' | sed 's/^/"mkdir -p" /' | sh


Reply With Quote