I have a folder with files, would like to output the contents of the individual files in a loop, but it doesn't work. Unfortunately, the name is not given.
What I tried:
cat \[ADV]\ ...
But it doesn't work.
If I change the filename for example ABC
then it works. What am I doing wrong?
Examples of files:
[ADV] DFN-CERT-2018-0399 PHP- Eine Schwachstelle ermöglicht einen Denial-of-Service-Angriff.eml
[ADV] DFN-CERT-2018-0409 PostgreSQL- Eine Schwachstelle ermöglicht die Eskalation von Privilegien.eml [ADV]
DFN-CERT-2018-0422 Tor- Zwei Schwachstellen ermöglichen Denial-of-Service-Angriffe.eml
CodePudding user response:
Put the literal parts of the filename inside quotes, while keeping the *
(the intended glob character) unquoted. Thus:
#!/bin/bash
for file in '[ADV] '*.eml; do
echo "FILE = ${file}:"
cat <"${file}"
echo
done
...this prevents [ADV]
from being treated as a glob expression that matches exactly one character, either A
, D
or V
, which would be its meaning when unquoted.
CodePudding user response:
Something like this should work as a FOR/DO LOOP.
#!/bin/bash
MY_IFS=$IFS
IFS=$(echo -en "\n\b")
for file in `ls \[ADV\]\ *.eml`; do
echo "FILE = ${file}:"; cat "${file}";
echo;
done
IFS=$MY_IFS