Shell programming

edited April 2005 in Software
I'm trying to write a pure-bash random image script. (thttpd is working perfectly, i'm not installing perl/php and apache for one script) I've got the actual random-numbering working fine (in a seperate script), I can get the value it returns, but how do I make the main script take that number and return a filename depending on which one it is? I'm thinking that I should do something like:
if [ $? = 1 ]; then return "1.png"; fi
but I can't return a non-numerical value. How do I return a filename?

BTW, don't tell me to just install Apache and PHP, i don't have space (225mb /) nor do I need all that for something as low-demand as my server. Sure, the script will select a random avatar, but PHP would be overdoing it if I was to install it just for one simple script.

Comments

  • The user and all related content has been deleted.
  • OK, I'll try that.
  • This is what I have so far:

    avatar.png:
    #!/bin/sh
    
    ./random.sh | ./pic.sh
    

    random.sh:
    #!/bin/sh
    
    cd pics
    set *
    shift $(($RANDOM % $#))
    echo "$logos/$1"
    

    and pic.sh:
    #!/bin/sh
    
    echo "Content-type: image/png"
    cat pics$1
    

    Should I send the content type before random.sh and pic.sh? Also, since I copied those in, I've since modified pic.sh.
  • The user and all related content has been deleted.
  • After much Googling, I came up with this:
    #!/bin/sh
    
    echo Content-type: image/png
    cd pics
    set *
    shift $((RANDOM % $#))
    cat < "$1"
    
    It works fine from the command line, but Firefox says that it contains errors.
  • The user and all related content has been deleted.
  • Nothing there.
  • View it in IE, that displays errors, I use it when I'm working on my sig
  • <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
    <BODY></BODY></HTML>

    I was right, time to fix thttpd...
  • The user and all related content has been deleted.
  • The user and all related content has been deleted.
  • I wonder if it's thttpd. I'll post a question to the mailing list.
Sign In or Register to comment.