Learning bash and I was thinking whether this is possible, with case or with some function..
For example..
./test.sh arg1 -p help,contact -e html,php # don't know how to expand them both
OR is it possible to do something like this?
./test.sh arg1 -p help -p contact -e html -e php
or
./test.sh arg1 -p help -e html -p contact -e php
I want the output to be like..
URL is www.google.com/help.html
URL is www.google.com/contact.php
code:
var1=$1
url="http://www.google.com/"
# maybe use a for loop here??
# Okay now if I use getopts - @Hannu
while getopts ":p:e:" o; do
case "${o}" in
p)
page+=("$OPTARG")
;;
e)
extension+=("$OPTARG")
;;
esac
done
shift $((OPTIND -1))
#I need a better for loop here - which can expand both variables
for val in "${extension[@]}"; #
do
# FAIL - pass first switch arguments -p and -e to for loop
echo "URL is http://www.google.com/$page.$val
done
OUTPUT: # closest I can get to.. first -p argument
./test.sh -p help -p contact -e html -e php
$ man getopt
# one way to goextension
array, but not overpage
array. Do you want to combine page names and extensions one to one or one to all? If first - you needfor (())
loop with index variable to iterate over both arrays. If second - you need two nested loops