Skip to main content
added 97 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

If switching to zsh is an optionoption¹, 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.

See also the Z parameter expansion to tweak how the parsing is done. For instance, if the file contains comments (with #) which should be ignored and has more than one line, you'd want:

ls -ld -- "${(Q@)${(Z[Cn])$(</tmp/files.txt)}}"

See info zsh flags for details.


¹ I hear zsh is now the default interactive shell in newer versions of macos

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.

See also the Z parameter expansion to tweak how the parsing is done. For instance, if the file contains comments (with #) which should be ignored and has more than one line, you'd want:

ls -ld -- "${(Q@)${(Z[Cn])$(</tmp/files.txt)}}"

See info zsh flags for details.

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.

See also the Z parameter expansion to tweak how the parsing is done. For instance, if the file contains comments (with #) which should be ignored and has more than one line, you'd want:

ls -ld -- "${(Q@)${(Z[Cn])$(</tmp/files.txt)}}"

See info zsh flags for details.


¹ I hear zsh is now the default interactive shell in newer versions of macos

added 293 characters in body
Source Link
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.

See also the Z parameter expansion to tweak how the parsing is done. For instance, if the file contains comments (with #) which should be ignored and has more than one line, you'd want:

ls -ld -- "${(Q@)${(Z[Cn])$(</tmp/files.txt)}}"

See info zsh flags for details.

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.

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.

See also the Z parameter expansion to tweak how the parsing is done. For instance, if the file contains comments (with #) which should be ignored and has more than one line, you'd want:

ls -ld -- "${(Q@)${(Z[Cn])$(</tmp/files.txt)}}"

See info zsh flags for details.

Source Link
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.