Wiki source for BashLoops
=====Bash Loops and Lists=====
return to DevBash
====Code====
%%(bash)
#!/bin/bash
# note: the first path will not be expanded below
PATH_LIST="~/tmp
/home/klenwell/tmp"
function loop_list() {
for i in /tmp /tmp/asdfghjk456
do
if [[ -e $i ]]; then
echo "path $i exists"
else
echo "path $i does not exist"
fi
done
for p in $PATH_LIST
do
if [[ -e "$p" ]]; then
echo "path $p exists"
else
echo "path $p does not exist"
fi
done
}
#
# Main
#
loop_list
%%
====References====
http://tldp.org/LDP/abs/html/loops1.html
http://www.cyberciti.biz/faq/bash-for-loop/
return to DevBash
====Code====
%%(bash)
#!/bin/bash
# note: the first path will not be expanded below
PATH_LIST="~/tmp
/home/klenwell/tmp"
function loop_list() {
for i in /tmp /tmp/asdfghjk456
do
if [[ -e $i ]]; then
echo "path $i exists"
else
echo "path $i does not exist"
fi
done
for p in $PATH_LIST
do
if [[ -e "$p" ]]; then
echo "path $p exists"
else
echo "path $p does not exist"
fi
done
}
#
# Main
#
loop_list
%%
====References====
http://tldp.org/LDP/abs/html/loops1.html
http://www.cyberciti.biz/faq/bash-for-loop/