Frequently forgotten things
IF statements
#!/bin/bash
i="Hello"
if [[ $i = "Hello" ]] ; then
echo “Found hello”
fi
lovebox:[/tmp] $ ./1.sh Found hello
Note, only a single ']' used here.
#!/bin/bash
i="Hello"
if [ $i ] ; then
echo "Found hello"
fi
lovebox:[/tmp] $ ./1.sh Found hello
#!/bin/bash
if [ ! $i ] ; then
echo "Hello is missing"
fi
lovebox:[/tmp] $ ./1.sh Hello is missing
if [[ $OPS -lt $TARGET ]] ; then
RunID's
Generating runid's to generate unique file/directory names
RUNID=`date +"%y%m%d%H%M"`
RUNID=`date +"%y%m%d%H%M"`-$$
Loop structures
Zsh
% for i in {0..31}
do
echo lun resize /vol/vol1/lun$i 50456m
done
lun resize /vol/vol1/lun0 50456m lun resize /vol/vol1/lun1 50456m lun resize /vol/vol1/lun2 50456m lun resize /vol/vol1/lun3 50456m lun resize /vol/vol1/lun4 50456m lun resize /vol/vol1/lun5 50456m lun resize /vol/vol1/lun6 50456m lun resize /vol/vol1/lun7 50456m lun resize /vol/vol1/lun8 50456m lun resize /vol/vol1/lun9 50456m lun resize /vol/vol1/lun10 50456m ...