0

How should i concatenate multiple text files get by arguments in terminal using a script in Bash?

#!/bin/bash
while read $1
do 
cat $1 > cat.txt
done

I tried that example but it is not working.

Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
John S.
  • 1
  • 1

1 Answers1

0

You should use '>>' to concatenate ('>' will create a new file each time):

for file in "$@"
do
    cat $file >> result
done
Pablo
  • 307
  • 3
  • 8
  • 2
    Actually the proper way to do that is `for file in "$@"; do cat "$file"; done >result` with the redirection after the `done` and with proper quoting of `"$file"`` – tripleee Apr 16 '18 at 10:00