With variables
Code: Select all
#!/bin/bash
DESTPART="/mnt/sda2"
DESTDIR="rootbkup"
FILENAME="bkuproot.zip"
</proc/mounts grep $DESTPART>/dev/null
if [ "$?" = "0" ] ; then
[ ! -d $DESTPART/$DESTDIR ] && mkdir $DESTPART/$DESTDIR
[ -f $DESTPART/$DESTDIR/$FILENAME ] && rm $DESTPART/$DESTDIR/$FILENAME
zip -r9y $DESTPART/$DESTDIR/$FILENAME /root
else
echo "$DESTPART is not mounted, no changes made"
fi
Code: Select all
#!/bin/bash
</proc/mounts grep /mnt/sda2>/dev/null
if [ "$?" = "0" ] ; then
[ ! -d /mnt/sda2/rootbkup ] && mkdir /mnt/sda2/rootbkup
[ -f /mnt/sda2/rootbkup/bkuproot.zip ] && rm /mnt/sda2/rootbkup/bkuproot.zip
zip -r9y /mnt/sda2/rootbkup/bkuproot.zip /root
else
echo "/mnt/sda2 is not mounted, no changes made"
fi
one with variables in easily modified and more portable. Although your
text editor does accurate and fast search and replace if you didn't use
variables.
You can write your programs as you please. Either script does exactly the
same thing.
I tend to put my variables in lowercase, because it is easier for me to
read. Also, C convention uses lowercase variables.
When using variables, try and give them meaningful names.
~