
Untitled
By: a guest on
May 1st, 2012 | syntax:
None | size: 1.84 KB | hits: 14 | expires: Never
What's wrong with my bash script to iterate over files
#!/bin/bash
file="release-candidate-1.0.tar.gz"
patch_base="patch-1.0."
patch_extension=".tar.gz"
i="1"
while [ -f $file ]
do
echo $file
file="${patch_base}${i}${patch_extension}"
i=$((i+1))
done
# ./script.sh
file=release-candidate-1.0.tar.gz: Command not found.
path_base=patch-1.0.: Command not found.
patch_extension=.tar.gz: Command not found.
i=1: Command not found.
file: Undefined variable.
#
#!/bin/bash
file="release-candidate-1.0.tar.gz"
patch_bas="patch-1.0."
patch_extension=".tar.gz"
i="1"
while [ -f $file ]
do
echo $file
file="${patch_base}${i}${patch_extension}"
i=$((i+1))
done
for i in {1..10} ; do
file="${patch_base}${i}${patch_extension}"
if [ -f ${file} ] ; then
echo "Found ${file}"
else
echo "NO ${file}"
fi
done
file="release-candidate-1.0.tar.gz"
patch_base="patch-1.0."
patch_extension=".tar.gz"
i="1"
/bin/bash -vx script.sh
portsnap fetch
portsnap extract update
cd /usr/ports/shells/bash
make install clean
#!/usr/local/bin/bash
file="release-candidate-1.0.tar.gz";
patch_base="patch-1.0.";
patch_extension=".tar.gz";
last_patch=500;
got_all_files=1;
for (( i = 0; i <= $last_patch; i++))
do
if [ $i -eq 0 ]
then
if [ ! -f $file ]
then
got_all_files=0;
fi
else
file=$patch_base$i$patch_extension;
if [ ! -f $file ]
then
got_all_files=0;
fi
fi
done
if [ $got_all_files -eq 0 ]
then
echo "Missing files.";
exit;
fi
file="release-candidate-1.0.tar.gz";
for (( i = 0; i <= $last_patch; i++))
do
if [ $i -eq 0 ]
then
tar xzvpf $file
./install.sh
./services restart
else
file=$patch_base$i$patch_extension;
tar xzvpf $file
./patch.sh
fi
done