You are not logged in.

#1 2011-05-22 00:29:50

ScreenSilently
Member
Registered: 2011-04-20
Posts: 6

Ascii Art --> Echo

asd(){
           .--.             .---.
              /:.  '.         .' ..  '._.---.
             /:::-.  \.-"""-;` .-:::.     .::\
            /::'|  `\/  _ _  \'   `\:'   ::::|
        __.'    |   /  (o|o)  \     `'.   ':/
       /    .:. /   |   ___   |        '---'
      |    ::::'   /:  (._.) .:\
      \    .='    |:'        :::|
       `""`       \     .-.   ':/
                   '---`|I|`---'
                        '-'
}

echo $asd

how can i make something like this to work?

what i get now is:

1.sh: line 6: syntax error near unexpected token `o'
1.sh: line 6: `        __.'    |   /  (o|o)  \     `'.   ':/'

Offline

#2 2011-05-22 01:15:37

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Ascii Art --> Echo

bash functions expect bash commands. You either want to store that in a variable or use a heredoc, e.g.:

foo() {
cat<<EOF
           .--.             .---.
              /:.  '.         .' ..  '._.---.
             /:::-.  \.-"""-;` .-:::.     .::\
            /::'|  `\/  _ _  \'   `\:'   ::::|
        __.'    |   /  (o|o)  \     `'.   ':/
       /    .:. /   |   ___   |        '---'
      |    ::::'   /:  (._.) .:\
      \    .='    |:'        :::|
       `""`       \     .-.   ':/
                   '---`|I|`---'
                        '-'
EOF
}

Offline

#3 2011-05-22 01:16:24

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Ascii Art --> Echo

EDIT: doh, too slow!

asd="
           .--.             .---.
              /:.  '.         .' ..  '._.---.
             /:::-.  \.-"""-;` .-:::.     .::\
            /::'|  `\/  _ _  \'   `\:'   ::::|
        __.'    |   /  (o|o)  \     `'.   ':/
       /    .:. /   |   ___   |        '---'
      |    ::::'   /:  (._.) .:\
      \    .='    |:'        :::|
       `""`       \     .-.   ':/
                   '---`|I|`---'
                        '-'
"

echo $asd

or

asd() {
cat <<EOT
           .--.             .---.
              /:.  '.         .' ..  '._.---.
             /:::-.  \.-"""-;` .-:::.     .::\
            /::'|  `\/  _ _  \'   `\:'   ::::|
        __.'    |   /  (o|o)  \     `'.   ':/
       /    .:. /   |   ___   |        '---'
      |    ::::'   /:  (._.) .:\
      \    .='    |:'        :::|
       `""`       \     .-.   ':/
                   '---`|I|`---'
                        '-'
EOT
}

asd

Last edited by fukawi2 (2011-05-22 01:17:22)

Offline

#4 2011-05-22 01:19:45

Wey
Member
Registered: 2011-04-22
Posts: 217

Re: Ascii Art --> Echo

You have to escape some of the special characters (  ` should be \` , " should be \" and \ should be \\. Putting the hole string in $" ... " literals will do the rest of the magic. See man bash, under the headline "quoting" for more details.

#!/bin/bash

echo $"
           .--.             .---.
          /:.  '.         .' ..  '._.---.
         /:::-.  \\.-\"\"\"-;\` .-:::.     .::\\
        /::'|  \`\\/  _ _  \\'   \`\\:'   ::::|
    __.'    |   /  (o|o)  \\     \`'.   ':/
   /    .:. /   |   ___   |        '---'
  |    ::::'   /:  (._.) .:\\
  \\    .='    |:'        :::|
   \`\"\"\`       \\     .-.   ':/
               '---\`|I|\`---'
                    '-'
"

should procude:

           .--.             .---.
          /:.  '.         .' ..  '._.---.
         /:::-.  \.-"""-;` .-:::.     .::\
        /::'|  `\/  _ _  \'   `\:'   ::::|
    __.'    |   /  (o|o)  \     `'.   ':/
   /    .:. /   |   ___   |        '---'
  |    ::::'   /:  (._.) .:\
  \    .='    |:'        :::|
   `""`       \     .-.   ':/
               '---`|I|`---'
                    '-'

edit: /mpfh too slow as well.

Last edited by Wey (2011-05-22 01:21:12)

Offline

#5 2011-05-22 15:46:02

ScreenSilently
Member
Registered: 2011-04-20
Posts: 6

Re: Ascii Art --> Echo

OK, thank you guys!

Offline

#6 2011-05-22 16:36:42

Vain
Member
Registered: 2008-10-19
Posts: 179
Website

Re: Ascii Art --> Echo

Hi,

you don't need to worry about that escaping stuff when placing quotes around the heredoc-delimiter ("EOT"). So this works:

asd() {
cat <<"EOT"
               .--.             .---.
              /:.  '.         .' ..  '._.---.
             /:::-.  \.-"""-;` .-:::.     .::\
            /::'|  `\/  _ _  \'   `\:'   ::::|
        __.'    |   /  (o|o)  \     `'.   ':/
       /    .:. /   |   ___   |        '---'
      |    ::::'   /:  (._.) .:\
      \    .='    |:'        :::|
       `""`       \     .-.   ':/
                   '---`|I|`---'
                        '-'
EOT
}

asd

Offline

Board footer

Powered by FluxBB