Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 644  / 1 Year ago, thu, march 16, 2023, 4:41:52

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?


More From » banner

 Answers
4

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
_ ____ __ _
_ __ (_)_ __/ ___|_ __ __ _ / _| |_
| '_ | / / | | '__/ _` | |_| __|
| | | | |> <| |___| | | (_| | _| |_
|_| |_|_/_/_____|_| __,_|_| __|

[#42] Friday, March 17, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
turhizz

Total Points: 82
Total Questions: 106
Total Answers: 96

Location: South Korea
Member since Mon, Dec 6, 2021
2 Years ago
turhizz questions
;