Find the answer to your Linux question:
Results 1 to 3 of 3
This probably isn't the best way to do this, but it sort of works. Code: echo "#CMS.sh" echo -n "Title of post: " read title echo -n "Text: " read ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    1

    Help with my "CMS" in bash

    This probably isn't the best way to do this, but it sort of works.
    Code:
    echo "#CMS.sh"
    echo -n "Title of post: "
    read title
    echo -n "Text: "
    read text
    echo "<i>" >>date
    date >>date
    echo "</i>" >>date
    echo "<p>" >>new.html
    cat date >>new.html
    echo "</p>" >>new.html
    echo "...................." >>new.html
    echo "<h1>"$title"</h1>" >>new.html
    echo $text >>new.html
    cat index.html >>old.html
    cat old.html >>index.html
    cat new.html >>index.html
    rm -f new.html old.html date
    what I want to do is add new text to an html file so that it appears at the top of the page.

    The following is what I get when I run it:
    Code:
        Tue Apr 15 22:34:48 CDT 2008
        ....................
        old title
        old text
    
        Tue Apr 15 22:34:53 CDT 2008
        ....................
        new title
        new text
    
        Tue Apr 15 22:34:48 CDT 2008
        ....................
        old title
        old text
    I'm trying to get it to look like

    <new post>
    <old post>

    Thanks in advanced for any help.

  2. #2
    Just Joined! wildpossum's Avatar
    Join Date
    Apr 2008
    Location
    Sydney/Australia
    Posts
    92
    Read all about BASH Programming - Introduction HOW-TO scripting as a starter.

  3. #3
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by trem View Post
    I'm trying to get it to look like

    <new post>
    <old post>

    Thanks in advanced for any help.
    So, what you need is to *reverse* the order in which the posts are stored, if I got it correctly.

    You can't do that directly, but there's an easy way. Let's say that you store all the posts in a file called posts.txt. You can dump the new info into tmp.txt with echo, then cat posts.txt >> tmp.txt, and finally rename that file what will be the new posts.txt.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...