#!/bin/kill-9.hobbiton.org

news:

stuff to click

home
blog
read news
linux & me
* shell scripting *
unix shells
what is kill-9?
BOFH
got geek?
l33tsp33k
 
hi morgen!

tools used

proud to be WYSIWYG free!

Chris's lack of artistic ability has been cleverly disguised by the GIMP

php

Apache, jump on it!

Powered by openBSD

webbak 2: fun with variables

the second example of webbak calls for you to write long cryptic lines of commands and arguments. there is nothing wrong with long lines, but they are a pain to type, and they leave you more room for typos which will cause errors when you run your script. fortunately, in all things unix, there is a better way. you can use variables to represent anything. here's how:
variablename=variablevalue
then you use the variable anywhere you want like this:
$variablename

by using variables, webbak becomes much simpler to type and to debug:
#!/bin/sh
webpath=/path/to/www
bakpath=/path/to/bakup
bakname=www_bakup_`date '+%d-%B-%Y'`
ls -lR $webpath > $bakpath/$bakname.txt
tar -zcvpf $bakpath/$bakname.tar.gz --directory $webpath

  1. #!/bin/sh
    first you call the interpreter like any other script.
  2. webpath=/path/to/www
    bakpath=/path/to/bakup
    bakname=www_bakup_`date '+%d-%B-%Y'`

    then declare variables, variablename=variablevalue style.
  3. ls -lR $webpath > $bakpath/$bakname.txt
    do the ls just like before, only using vairables instead of long strings.
  4. tar -zcvpf $bakpath/$bakname.tar.gz --directory $webpath
    create the tarball just like before, using variables this time.
webbak, my first shell script
webbak 2, the sequel
getnews, your news authority
su.bat, superuser for NT
sed tutorial, very informative
    home     blog     read news     linux & me     * shell scripting *     unix shells   what is kill-9?     BOFH     got geek?     l33t