I am new to bash and I need to write an if statement within my code however I am unsure how to write is so that if $someVar
is found then run this else do that. In this case $someVar
is a file and I am not wanting to output text just run another line of code in this case creating the file.
Code:
rm /var/path/to/folder/$someVar
for i in `seq 3 253`
do
echo $ALLOCATION.$i >> /var/path/to/folder/$someVar
if [[ -n $someVar ]]; then .. do your stuff .. fi
Any bash reference will explain andman bash
will also explain the type of conditional expressions (or tests) available.$someVar
is set and is not empty? To test if a file with the name held by$someVar
exists, it isif [[ -f $someVar ]]; then ... do your stuff ..fi
. You can also just use a compound command to check and conditionally remove the file[[ -f $someVar ]] && rm /var/path/to/folder/$someVar