Nice one.Rava wrote:But it's not about creating the folder, it's about finding it.


Nice one.Rava wrote:But it's not about creating the folder, it's about finding it.
Really funny stuff can happen when you are very very tired, In German we call that "schlaftrunken", you could translate into "drunk on sleeplessness" or "drugged with sleep", and it indeed is similar to drug overdoes, minus all the negative issues of drugs, you only have a weird experience and body & should not need to suffer...Bogomips wrote:Nice one.Rava wrote:But it's not about creating the folder, it's about finding it.Instead of counting sheep, fell asleep trying to solve problem of making directory with spaces, as well as directory path including directory with spaces.
Code: Select all
mkdir -p /tmp/play/"path with"/spaces
touch /tmp/play/path\ with/spaces/file.txt
find /tmp/play -name "file*" | xargs -n1 -i rm {}
Indeed that works, usually lazy me just fires up mc instead, that one is usually able to remove even the weirdest of files. Like a file or folder called "*" (without the ", or with the "), or files with Carriage return in them, many scripts file name handling fail due to assuming a line they find is always a file name, never thinking of the possibility that a filename can contain more than one line.brokenman wrote:Code: Select all
mkdir -p /tmp/play/"path with"/spaces touch /tmp/play/path\ with/spaces/file.txt find /tmp/play -name "file*" | xargs -n1 -i rm {}
Bogomips wrote:^ Such a precise answer, that haven't a clue which issue is being addressed.
There is no mention here that the final aim is to delete the file.Rava wrote: You can boil it down to this:
I want to call mc (via a script) with 2 paths. So that mc opens these "target path" in its left and right working panel, one is the source directory for backup copy, the other the target. The target directory in /tmp varies since I give it a name including version and date so that I can have several versions next to each other.
Both have whitespace. One also has a wildcard. (The one in /tmp)
The path with only whitespace you can enclose in " ". (In my example, the one in /home/rava, but could be anywhere with a needed path with whitespace)
The other one, you cannot use " " to protect the whitespaces, or else the wildcard * won't expand.
That's an how it forks fine in bash itself, but not in a bash script. When you created a matching folder, e.g.Code: Select all
# file /tmp/999-local-settings-3.1.*/home/rava/.moonchild\ productions/pale\ moon
the above would match, like I demonstrated with bash in my above post.Code: Select all
# mkdir -p "/tmp/999-local-settings-3.1.0_2016-04-17/home/rava/.moonchild productions/pale moon"
But when you try the same in a bash script, it fails. You get an "file or folder not found", or such error.
Like I said above, using " " won't work, since the * won't expand.
Using "\ " (minus the " ) also not works, the bash script complains about "path not found", even when the same works fine in bash itself....
That's boiled down to the basics. Well, at least I found a 2 part work around as quoted above, but I would prefer a solution in being able to give such wildcard and whitespace folder or filename and the script is able to expand the wildcard(s) while still respecting the whitespaces.
Please don't make a overly long or full quote for no reason. Please link to the article itself like soBogomips wrote:There is no mention here that the final aim is to delete the file.