Skip to main content
1 of 3
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

If switching to zsh is an option, you could use its z and Q parameter expansion flags that are designed for that:

file_content=$(</tmp/files.txt)
quoted_strings=(${(z)file_content})
strings_with_one_layer_of_quotes_removed=("${(Q@)quoted_strings}")
ls -ld -- "$strings_with_one_layer_of_quotes_removed[@]"

Or all in one go:

ls -ld -- "${(Q@)${(z)$(</tmp/files.txt)}}"

That assumes the syntax of the quoting in the file is compatible with that of zsh.

Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k