Skip to content
Advertisement

Concatenating file names into string for a function

I’m trying to concatenate a bunch of files into a string so I can use them for a function. As a test script I’m trying to do this:

#!/bin/bash

for line in $(cat list.txt)
do
  x=" "
  A=$A$line$x
done

echo "$A"

mv "$A" ./stuff

but I’m getting the error:

 mv: cannot stat ‘x.dat y.dat z.dat ’: No such file or directory

but they are most definitely there

can I get some advice please?

Advertisement

Answer

  1. Change the last line to mv $A ./stuff

That should work with files that do not have space in their names.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement