|
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
- #!/bin/sh
first you call the interpreter like any other script.
- webpath=/path/to/www
bakpath=/path/to/bakup
bakname=www_bakup_`date '+%d-%B-%Y'`
then declare variables, variablename=variablevalue style.
- ls -lR $webpath > $bakpath/$bakname.txt
do the ls just like before, only using vairables instead of long strings.
- tar -zcvpf $bakpath/$bakname.tar.gz --directory $webpath
create the tarball just like before, using variables this time.
|