Bash.org script

I wanted a script to show a random quote from bash.org in every new terminal session. PHP is my language of choice. :) Save as “bashquote” and chmod 755 (rwxr-xr-x) to use (make sure the regexp looks exactly as below in preg_match_all()). The script only works in a Unix/Linux environment.

Edit 15. april 2015: The code has been moved to Github! :)

Leave a comment

8 Comments

  1. Why did you write it in php?
    Not sure this qualifies as a bash script as long as the whole thing is put in a .

    You can easily just rename the file and run in on a webpage.

    Should try doing it in actual bash, and not use another language hidden in a .sh script.

  2. omg. nevermind.
    lol : D

  3. Juaco

     /  26. March, 2010

    Here you have one in bash, stop complaining!

    #!/bin/bash

    quotefile=”${0%/*}/Quotes”
    funny=1

    if [ “$1” == “gimmemore” ]; then
    ping -c 1 bash.org &> /dev/null
    [ $? == “0” ] && elinks -dump http://bash.org/?random$funny | sed -n ‘/^.*ModApp.*_____$/,/^.*Home.*Latest.*$/{/^.*ModApp.*_____$/d;p;}’>$quotefile
    exit 0
    fi

    quote=$[$RANDOM%$[$(sed -n ‘/^.*]#.*$/p’ “$quotefile” | wc -l)-2]+1]
    quote=$(bash -c “cat -n “$quotefile” | sed -n ‘/^.*]#.*$/p’ | sed -n “${quote}p” | sed ‘s/^ *([0-9]+).*$/1/g'”)
    sed -n “$quote,/^.*]#.*$/{$quoted;/^.*]#.*$/d;p}” $quotefile

  4. Haha, that’s awesome! :)

  5. Or even;
    #!/bin/bash
    curl “http://bash.org/?random1” 2>/dev/null | ack -1o ‘(.*)’ –output=’$1′ | sed “s/>/>/g” | sed “s/</</g"

    requires curl (curl.haxx.se) and ack (betterthangrep.com) — two excellent commandline tools :)

  6. Umm. The two last sed’s should be & gt ; and & lt ; (w/o spaces – got escaped).

  7. Or even;
    #!/bin/bash
    curl “http://bash.org/?random1″ 2>/dev/null | ack -1o ‘<p class=”qt”>(.*)</p>’ –output=’$1′ | sed “s/& gt ;/>/g” | sed “s/& lt ;/</g"

    requires curl (curl.haxx.se) and ack (betterthangrep.com) — two excellent commandline tools :)

  8. No, thanks, I prefer my programs readable and maintable. :p I’m sure you could do it in Brainfuck too if you wanted to. ;)

Leave a Reply