Bash Loops and Lists
return to DevBashCode
#!/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
# 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.htmlhttp://www.cyberciti.biz/faq/bash-for-loop/
[There are no comments on this page]