Loop Script and not opening files containing spaces
Hello,
I wrote a simple script, that basically wait for a *.dat-file in a certain folder, which is always a zipped file and extracts it.
It worked before and i changed nothing in the script, but since last week i have the problem, that it doesnt extract files containing a space. How do i make it also extract files containing spaces again?
If found something with
but it doesnt seem to work.
and another problem i have is, i am looking for pictures in the extracted files, but if no *.png or *.jpg files are found it still opens the literal "*.jpg" and "*.png"-files in sublime, how can i make it, that if no pictures are found, it doesnt open that file or sets "${BILDER_JPG[@]}" "${BILDER_PNG[@]}" to "" ?
.
.
.
It worked before and i changed nothing in the script,
.
.
.
... a bit difficult to believe ...
Quote:
but since last week i have the problem, that it doesnt extract files containing a space
.
.
.
for file in $(ls $DOWNLOAD_DIR/*.dat)
double quote the "command substitution", or replace by just for file in $DOWNLOAD_DIR/*.dat
can't possibly work, and never has - it yields an error message like
The
command doesn't exist and leads to an error message.
The alt: command doesn't exist and leads to an error message.
So far for the obvious. Some more comments:
- your indentation of the script doesn't help in understanding but obfuscates it.
- Using date by the second for creating temp files / directories you might be pushing your luck as the loop might finish in below a second leading to ambiguities.
- Above remark on "command subst" is valid for the other for loops in your script as well.
- appending echoes to a log file umpteen times in a for loop is far less efficient than redirecting the entire loop's output once only at the end of the loop.
- echoing four times for four line feeds is less efficient than writing four line feeds in one single echo - or, even better, print all line feeds within the awk script. Did you consider removing the entire for loop in favor of one single awk script?
Quote:
and another problem i have is, i am looking for pictures in the extracted files, but if no *.png or *.jpg files are found it still opens the literal "*.jpg" and "*.png"-files in sublime, how can i make it, that if no pictures are found, it doesnt open that file or sets "${BILDER_JPG[@]}" "${BILDER_PNG[@]}" to "" ?
For this problem you seem to already have found and implemented a solution - what else do you need?
If you remove the ls, the loop will work just fine.
I imagine blend_in was using ls *.dat to get rid of a stray *.dat if there are no .dat files in the directory. Given that you are using bash in this case, adding the following line to the top of the script will not only avert the need for the ls, but help with the problem of stray *.png non-files mentioned later in the original post:
I have a folder with files and I have to process them in a loop. However the filenames have space characters, so the list get split.
$ touch "File Number_1"
$ touch "File Number_2"
$ ls "/tmp/File Number"_*
/tmp/File Number_1 /tmp/File Number_2
I tried following (sorry for using the... (3 Replies)
Hi Experts,
Need some help regarding a requirement --
I may get any number of zipped files in a month (max 36). each of those wil contain a detail file and a header file. Also when the files arrive, there will already be previous days file lying around.
What I am trying to do is count the... (5 Replies)
Hi all,
I've been tangoing with this one for a couple of days now and I'm still not making any progress.
Basically I'm trying to match three numbers in a string from a text file with matching numbers in a jpeg, and then copying the results to another folder.
Data looks like this:
Model:... (4 Replies)
I developed a perl code..And the excerpt from it is given below...
open(HANDLE,$cmp_path) ; #reading the xml file from the file path
while($file_path = <HANDLE>)
I have list of XML files to read from a folder. It has some spaces inside the name of the file...I used "\"... (2 Replies)
Dear All,
i facing problem to use string having spaces in for loop..
file used for FOR LOOP
command.txt
rpm -t -v ttm -D -r RJLL -h YELP
rpm -t -v ttm -D -r RJLL -h ERRT
rpm -t -v ttm -D -r RJLL -h TYYE
rpm -t -v ttm -D -r RJLL -h POOL
CODE using for execute above command... (3 Replies)
Hi there,
I don't understand the following behavior:
toto:~$ for word in un "deux trois"; do echo $word; done
un
deux trois
toto:~$ sentence='un "deux trois"'
toto:~$ for word in $sentence; do echo $word; done
un
"deux
trois"
toto:~$ sentence="un 'deux trois'"
toto:~$ for word in... (10 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,
I have a total of ten file to open in the Perl script and i am using a for loop to open each file and capture some strings inside each file.
Unfortunately, i encounter the below syntax error.
I think there should be something wrong with this term reports_${counting}_${_}.txt but i do... (4 Replies)
I'm a new to UNIX/LINUX. I just put cygwin on my laptop and I can navigate around the directories, but I can't open files (.doc, .ppt, .html or .exe). Is there an explicit command to do this? I know that in Solaris when it does not recognize the file, it brings up the list of available viewing... (4 Replies)