I am trying to output following ascii character art every time my terminal loads:
__ __ _
/ / / /___ ____ _____ _(_)
/ / / / __ \/ __ / /
/ /_/ / / / / /_/ / /_/ / /
\____/_/ /_/\__,_/\__, /_/
/____/
So I added following at the end of .bashrc
:
echo " __ __ _
/ / / /___ ____ _____ _(_)
/ / / / __ \/ __ `/ __ `/ /
/ /_/ / / / / /_/ / /_/ / /
\____/_/ /_/\__,_/\__, /_/
/____/ "
And it prints:
It seems that it is misinterpreting slash in ascii art as escape sequence, that why it is printing -bash: /: Is a directory
. How can I get rid of it? If I add something simple to .bashrc
, like echo "Hello World!!"
, it does not print this error message.
Use the single quote instead:
echo \
' __ __ _
/ / / /___ ____ _____ _(_)
/ / / / __ \/ __ `/ __ `/ /
/ /_/ / / / / /_/ / /_/ / /
\____/_/ /_/\__,_/\__, /_/
/____/
'
Try like this:
text=(
' __ __ _'
' / / / /___ ____ _____ _(_)'
' / / / / __ \/ __ `/ __ `/ /'
'/ /_/ / / / / /_/ / /_/ / /'
'\____/_/ /_/\__,_/\__, /_/'
' /____/'
)
printf '%s\n' "${text[@]}"
For a multi-line text literal, a HereDoc is very appropriate:
# Use a quoted heredoc 'marker' to disable expansion of backticks
cat <<'LOGO'
__ __ _
/ / / /___ ____ _____ _(_)
/ / / / __ \/ __ `/ __ `/ /
/ /_/ / / / / /_/ / /_/ / /
\____/_/ /_/\__,_/\__, /_/
/____/
LOGO
Un-quoted heredoc marker:
cat <<EOF
hello `echo world`
EOF
Output:
hello world
Quoted heredoc 'marker':
cat <<'EOF'
hello `echo world`
EOF
Output:
hello `echo world`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.