Directories with spaces in name - looking for help with questions in that issue
I need to work with 'nice' directory names which have some spaces in name, and that brings some questions and not-understanding.
Would some expert help me out how to deal with that?!
My task is to document some processing, running from some script. I do need to have spaces in directories names, and those directory dynamic - in term of depend on processing way.
My actions are:
1. check if directory exist
2. if not - create it
3. use it to copy file to it.
I make a function to check a directory. Generaly speacking, it's doing next:
That works fine until the received directory is in one level. For 2 level unexistend dir it does not work.
I mean if received dir is "lev_1/lev_2/" and ./lev_1 does not exist, the "mkdir" has error.
I see a solution to parce the received dir by the '/' and check for every level and create it if nessesary.
I've used 'nawk' for that:
It result as expected:
Now I need to check those dirs for existance and mkdir if nessesary.
And here problems start!
First attempt is to use shell command inside the nawk block. So, instead of 'print curr' I would do some shell 'if..then..fi'
1. But how to pass the nawk variable to shell command? (this is first question)
Well, can't do from nawk, let nawk pass dirs out to shell, and process it outside of nawk.
I could use 'for .. in ..'
This way works fine untill spaces in dir-name.
Now the last dir is broken on space:
Ok, need to put quotations around: 2. Here I do not understand why it is happend this way? Why double quotation treated as a part of the string, but not as an indicator of string beginning and end?,
This way it is working fine:
To print it as one string does not halped also:
I've tryed to set array with dirs. Again the same result:
.. but
Also I've tried to add '\' to space - does not work:
Could anyone give me some highlight why I could not get space processed as a part of string?
Also, I am out of idea how to be with the spaces in dir name.
I would appreciate any suggestions on this mater, also.
Last edited by alex_5161; 02-29-2008 at 04:16 PM..
...
Why not just use the -p flag to mkdir? Might save some effort...
Well, just because I did not know that!
Definitely, it is solution to that task! Thank you!
But raised questions still do not let me slip well (at work, at least )
- How to pass 'nawk' variables to a shell command, called inside of nawk?
- Why the double-quoted strings, produced by nawk are treated differently than the same string, typed in command line? (a space in double quoted string from nawk still processed as a word separator, and double-quotes are treated as a part of string, instead of as string boundaries.)
Quote:
Originally Posted by Smiling Dragon
I must confess, I stopped reading at the part where you talk about the need to make each level directory as you go.
...
I am agree, it is comes out as a big and uncomfortable to read post.
Later I will edit it to make shorter and more obvious in questions.
Hi
I have a list file with complete path of files and there are directories with spaces. Now when i read the list file, read the line and read the file it says no file found because of the space. How can I get through this issues
for file in $(<list_file.txt)
do
first_line=`head -1... (8 Replies)
My code
path=`find /root/folder/ -maxdepth 100 -type d | sort --random-sort | head -1`
if this returns a directory with spaces in for instance:
/root/folder/this is a folder
is there a way to replace the value of path with the same value but with the spaces replaced so its... (2 Replies)
Hi all,
I've a requirement as below
Source file src.txt sample data:
A<10 white spaces>B12<5 white spaces>C<17 white spaces>
A1<5 white spaces>B22<5 white spaces>C13<17 white spaces>
when I'm fetching a record from this file into a shell variable like below:
vRec=`head -1 src.txt... (2 Replies)
Hi,
I am writing a shell script to build Java options dynamically in a variable array and pass them to java.exe. If an option value contains a space, I cannot find a way to get it interpreted correctly. Here is my example:
#!/bin/bash
JAVA_HOME=/opt/jvm/jre1.5.0_18
JAVA_OPTS=("-Xms256m... (4 Replies)
All, I have a cleanup script that removes directories and all contents underneath, but I am having issues with directories with spaces.
This is the command I am currently running, how can I get it to work with directories with spaces?
find /path -mindepth 3 -type d -exec rm -rf {} \; (29 Replies)
Hi,
I have a small issue while using variables for a file name in UNIX.
I have file name like "abc def 123.txt"
Folder will be in /zzz/xxx/yyy
I created 2 variables Folder = '/zzz/xxx/yyy'
file = 'abc def 123.txt'
While using this in grep command i am... (6 Replies)
Hi
I need a script that can search through a set of directories and can locate any file or directory that has a space at the end
Filename(space)
Foldername(space)
I then need to remove that space within the script
Hope someone can help
thanks in advance
Treds (8 Replies)
Hi all,
my problem:
(little extract from my bash-script)
I want to move each file (.mov) from one directory (and many Subdirectories) to another directory (only one);
after moving i want to create hardlinks to the old directories.
Thatīs no problem, but now:
source-directories... (4 Replies)
I am getting the different accessing permissions for the directories ,for some directories it is drwxr-sr-x, for some other directories it is like drwxr-xr-x.
what is the difference between these 2 access permisions of the directories? (1 Reply)