2

I have the following command saved in mat.txt file:

printf "
       _       ____            __ _
 _ __ (_)_  __/ ___|_ __ __ _ / _| |_
| '_ \| \ \/ / |   | '__/ _` | |_| __|
| | | | |>  <| |___| | | (_| |  _| |_
|_| |_|_/_/\_\\____|_|  \__,_|_|  \__|

"

when I execute this file after made it executable using:

chmod +x mat.txt

It gives me an Error:

enter image description here

It's saying like command not found, file end reached when searching for ' & syntaxerror.

Anyone knows why?

Raffa
  • 34,963
Keeran
  • 187

2 Answers2

5

From man bash:

Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, , and, when history expansion is enabled, !.

In other words, " ... " is not sufficient to protect the unbalanced backtick on line 4 of your text; the shell is interpreting it as the start of a command substitution.

OTOH you can't use single quotes, because your text contains single quotes.

I'd suggest avoiding the issue of quoting altogether by using a here document. You should also use a shebang to make sure your file is interpreted by the intended shell. So:

#!/bin/sh

cat <<'TXT' _ ____ __ _ _ __ () / ___|_ __ __ _ / | | | '_ | \ / / | | '/ ` | || | | | | | |> <| |___| | | (| | _| | || ||//_\____|_| \,|| __|

TXT

then

$ ./mat.txt
       _       ____            __ _
 _ __ (_)_  __/ ___|_ __ __ _ / _| |_
| '_ \| \ \/ / |   | '__/ _` | |_| __|
| | | | |>  <| |___| | | (_| |  _| |_
|_| |_|_/_/\_\\____|_|  \__,_|_|  \__|
steeldriver
  • 142,475
0

You didn't ask for a specific interpreter in your question. Therefore, Python(which allows assigning a multi-line string to a variable using triple quotes be it single ''' ... ''' or double """ ... """) might be an option like so:

#!/bin/python3

a = ''' _ ____ __ _ _ __ () / ___|_ __ __ _ / | | | '_ | \ / / | | '/ ` | || | | | | | |> <| |___| | | (| | _| | || ||//_\____|_| \,|| __| '''

print(a)

Which executes like so:

$ ./mat.txt
   _       ____            __ _

_ __ () / ___|_ __ __ _ / | | | '_ | \ / / | | '/ ` | || | | | | | |> <| |___| | | (| | _| | || ||//_____|_| \,|| __|

Raffa
  • 34,963