0

Let files="apartment.flat my apartment1.flat"

I want to cat those files using cat $files

The problem is cat searches for apartment.flat, my and apartmrnt1.flat

What do i need to do in order to escape those spaces?

I tried files="apartment.flat 'my apartment1.flat'" And files="apartment.flat my\ apartment1.flat" Nothing works...

Thank!

Amit Enoch
  • 37
  • 1
  • 5

2 Answers2

3

You should use an array:

files=(apartment.flat "my apartment1.flat")
cat "${files[@]}"
chepner
  • 497,756
  • 71
  • 530
  • 681
-2

you just need to put $files within quotes, should help you

files="apartment.flat my apartment1.flat"

cat "$files"

This worked for me

$ files="apartment.flat my apartment1.flat"
$ echo $files 
apartment.flat my apartment1.flat

$ cat "$files"
hi how are you..
Community
  • 1
  • 1
Sanjeev
  • 107
  • 6