Cp/Mkdir and spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cp/Mkdir and spaces
# 1  
Old 06-14-2008
Cp/Mkdir and spaces

I am having trouble using cp and mkdir commands on a small script. The problem is I have spaces what I am trying to mkdir and then copy. Any suggestions on how I can solve this problem? I've tried searching online.

Code:
while read linefile
do  
  echo mkdir -p $CPP$linefile | cut -d / -f 1-5,8-12
  echo cp "$linefile" $CPP$linefile | cut -d / -f 1-11,14-18
done < /tmp/itunes_50.txt

I've tried \" but that didn't help. Thanks in advance.
# 2  
Old 06-14-2008
Try to quote all your variables and change the IFS temporary:

Code:
OIFS=$IFS
IFS=""

Do you stuff here..........

IFS=$OIFS

But.... you should avoid spaces in file and directory names.

Regards
# 3  
Old 06-14-2008
Sorry, I don't quite follow. Still learning.
# 4  
Old 06-14-2008
It should looks like:

Code:
#!/usr/bin/sh
.
.
.

OIFS=$IFS
IFS=""

while read linefile
do  
  echo mkdir -p "${CPP}""${linefile}" | cut -d / -f 1-5,8-12
  echo cp "${linefile}" "${CPP}""${linefile}" | cut -d / -f 1-11,14-18
done < /tmp/itunes_50.txt

IFS=$OIFS

.
.

Regards
# 5  
Old 06-15-2008
You do learn something new everyday. The code kind of worked. It what you said it would do, but no exactly what I wanted. I did change the script, but again another error. I know, most of you with bash experience will probably say this is some ugly code. I'm learning, deal with it.

Code:
while read linefile
do  
  MKK=`echo "$CPP$linefile" | cut -d / -f 1-5,8-10`
  echo mkdir -p "\"$MKK"\"
  # echo $MKK
  CCP=`echo "$linefile""\" "\""$CPP""$linefile" | cut -d / -f 1-11,14-18`
  echo cp "\"$CCP"\"
done < /tmp/itunes_50.txt

Now it works fine with the echo command. But when I get rid of the echo and just use cp or mkdir, it creates no directories and tells me I am not using the copy command correctly. I have tried different `"' but nothing I do seems to solve this problem.
# 6  
Old 06-15-2008
What is the output of these commands?

Code:
echo mkdir -p "\"$MKK"\"
echo cp "\"$CCP"\"

Regards
# 7  
Old 06-15-2008
Here's what I get...
Code:
mkdir -p "/Users/diegoa/Desktop/itunesdir/Music/Smashing Pumpkins/Mellon Collie And The Infinite Sadness - Dawn To Dusk"
cp "/Volumes/Diego_External/Music/Smashing Pumpkins/Mellon Collie And The Infinite Sadness - Dawn To Dusk/02 Tonight, Tonight 1.mp3" "/Users/diegoa/Desktop/itunesdir/Music/Smashing Pumpkins/Mellon Collie And The Infinite Sadness - Dawn To Dusk/02 Tonight, Tonight 1.mp3"

Which is perfect if I copy it and run it on the shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Mkdir

hi linux expert what is a difference between: mkdir test and mkdir ./test and also if ( -e /test ) then and if ( -e ./test ) then thanks in advance Please use icode or code tags next time for your code and data (1 Reply)
Discussion started by: abdossamad2003a
1 Replies

2. UNIX for Dummies Questions & Answers

How to use mkdir{...} with a variable?

Hi, I used "mkdir job{0001..10}" do get directories. Now I want to create directories with a variable, for exemple "mkdir job{0001..$a}". When a=5 I get the directory "job{0001..5}". What have i to change to get job0001,...,job0005 :/ Thx for ur help :) (1 Reply)
Discussion started by: E_taks
1 Replies

3. Homework & Coursework Questions

Mkdir

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Do the procedure, which if there are 5 parameters then it creates 4 directories with names of 4 parameters, in... (2 Replies)
Discussion started by: bolones
2 Replies

4. Shell Programming and Scripting

mkdir bug

Dear, I have the following script: maak_backup () { echo 'Maken van tijdelijke bestanden, even geduld aub.' for i in /home/yannick/* ; do cp -r $i $i.bac done if ; then echo 'Backup map = OK!' echo 'Bezig met kopiëren, even geduld... (9 Replies)
Discussion started by: yadeki
9 Replies

5. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

6. UNIX for Advanced & Expert Users

mkdir

Is there ant way to increase max number of folders in the directory from the 32766: Problem UFS: shell>mkdir mmm mkdir: mmm: Too many links But there are no links, just folders. shell>ls | wc -l 32766 (3 Replies)
Discussion started by: mirusnet
3 Replies

7. Shell Programming and Scripting

mkdir

Hi, I look for a script to create 150 directories : d000 d001 d002 ... ... d149 would you help me please ? I think it would be for i mkdir d$i Many thanks. PS : #uname -a AIX fserver 3 5 0050691A4C00 (2 Replies)
Discussion started by: big123456
2 Replies

8. Linux

install vs mkdir

I'm sitting here late at night, reading linux from scratch, and I come to this part: http://lfs.osuosl.org/lfs/view/stable/chapter06/creatingdirs.html my question to you, the all knowing unix.com'ers is this: what's the difference between using the install command as they do, and using the... (1 Reply)
Discussion started by: thmnetwork
1 Replies

9. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies

10. UNIX for Dummies Questions & Answers

mkdir limitations

What characters can't be used with a mkdir? Any limits on length of name? Thank you, Randy M. Zeitman http://www.StoneRoseDesign.com (12 Replies)
Discussion started by: flignar
12 Replies
Login or Register to Ask a Question