Show contents of a file by opening the file with the content string of a variable

Asked

Viewed 326 times

3

I have a problem showing the contents of a file using the following command:

variavel="Affonso\,\ I.\ P..txt"
cat < "$variavel"

And running the same command on the terminal but using no variable, it works normally like the following image:

inserir a descrição da imagem aqui

How can I fix this?

1 answer

1

You can do it like this:

variavel="$(< Affonso\,\ I.\ P..txt)"

echo "$variavel"
  • i tried with this code snippet of yours but unfortunately kept the error msg: . /show_var_arq.sh: line 3: Affonso, I. P.. txt: File or directory not found

  • I managed to make it work partially, now gave a problem that it lost the line breaks from the original text.

  • variable= cat < Affonso\,\ I.\ P..txt echo $variavel

  • @AGPC Updated the answer, see if it now works.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.