Search code examples
bashshellscriptingsh

File name too long bash


i want to copy some files from ../soft to ../copu_new. The name of that tests are in ../sim/soft.txt.

I had en error : cp:cannot stat '../soft/file1.txt\file2.txt\file3.txt': File too long

Follow the code below:

input="../sim/soft.txt"

while read line
do
 ##to skip the first line of the file
  a=$(tail -n +1)
 ##From string to table
  for i in $a
  do 
    table_soft[$i]="$i"
  done
  for i in "${tabke_soft[@]}"
  do 
    cp ../soft/$i ../copy_new
  done
done < $input

The file Soft.txt is :

###This all tests:
file1.txt
file2.txt
file3.txt

Solution

  • It's most likely the classic bash issue where trying to run an array through a for loop gives you all the content unless you wrap it in double quotes first. Try this..

    a="$(tail -n +1)"