January 16, 2008

bands script (bash scripting tutorial of sorts)

Filed under:lifestyle,music,technology — ryan @ 4:30 pm

I like to keep little lists, lately. It keeps me organized, sort of. If anyone has heard of or used the GTD (getting things done) system, they know what I am talking about. Anyhow, I am sick of forgetting bands that I find online that I really like, and would like to keep a wish list of albums to buy, so they are fresh in my mind and I can refer to the list if I get any disposable income.

So I wrote this script:

#!/bin/bash

# you can change the textfile variable to anything you want
# this allows you to make various lists and have different scripts
# for each.  simple but useful.
# I use it to make a list of albums I wanna get.

textfile=/Users/ryan/Music/bands-to-find.txt        #edit this line!!
filename=`basename $textfile`

if [ ${#} -lt 1 ]                   # if you are not adding something,
then                                # assumes you want to see file contents
    echo " "
    echo "— Contents of $filename: —"
    echo " "                        # let’s make a nice header/footer and
    cat -n $textfile                # show the file with line numbers :)
    echo " "
    echo "— End of $filename —"
    echo " "
    echo "Usage (to add a line)"    # then tell the dummy how to use it              
    echo "$ `basename $0` ‘line of text to add’ (use quotes!)"
else
    echo "$1" >> $textfile          # the actual simple command        
    echo "`basename $0`: added ‘$1‘ to $filename!"          # be proud!
fi

 

Basically it allows you to add a line to a text file easily and quickly, and if you just call the program up without wanting to add anything, it organizes the list and shows it to you prettily. This doesn’t have to be used for an album wish list (yet)..I could see someone modifying it for any sort of list…upcoming birthdays, baby names (haha babies), to-do list, videogame wishlist, etc. This is a super simple, but well-commented script that might be a good tutorial for anyone who wonders what good a shellscript can do, or wants to learn.

one comment so far »

  1. you love babies.

    Comment by Ev — January 17, 2008 @ 2:04 am

Copy link for RSS feed for comments on this post or for TrackBack URI

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)