0

I'm very bad at regex and escaping characters. I want to use the 'cat' command in a bash script like this :

echo `cat working-dir/*OUTPUT` ;

That should print on screen, every files in the working-dir that end with "OUTPUT" but this is not working

Later in that program, i would like to do this :

cat working-dir/*OUTPUT >> result_file.txt

But is not working either :( Can you help me please?

Gui O
  • 363
  • 4
  • 8
  • 22
  • Backticks are not quotes; you could fix this by using `echo "$(cat working-sir/*OUTPUT)"`, but the `echo` itself is unnecessary. – chepner Jan 21 '14 at 15:20

1 Answers1

3

Why are you using echo, or backticks, at all?

cat working-dir/*OUTPUT

Similarly,

cat working-dir/*OUTPUT >> result_file.txt

...certainly should work. Please provide a complete script for reproducing any failure that you see, including setup (creating working-dir, putting at least one file ending with OUTPUT into it, running the cat, and observing it to fail).

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • I feel so stupid. I searched for something too complicated... Thanks ! – Gui O Jan 21 '14 at 15:18
  • @JohnKugelman No, it won't work (in the sense of emitting output verbatim) -- it performs string-splitting and glob-expansion. Thus, if an `OUTPUT` file contained newlines, they would be transformed to spaces; if it contained a `*`, it would be replaced with a list of filenames; etc. Correcting this would require correcting the quoting. – Charles Duffy Jan 21 '14 at 15:19
  • @JohnKugelman I don't know exactly what you mean by "extra", but unquoted expansions certainly do glob-expand. Try creating a file containing only a `*` character and testing it yourself. – Charles Duffy Jan 21 '14 at 15:21