i learned bash very recently, and i'm trying to read arguments for my script. So i wrote this, but i get an error (and vim has highlited in pink the last double parenthesis in the 4th line)
#!/bin/bash
for (( i=1; i<=$#; i++ )); do
if [[ ${!i:0:1} == "-" ]] && ! [[ ${!i:1} =~ [^a-zA-Z]+ ]]; then
for (( j=1; j<=$(($(expr length ${!i})-1)); j++ )); do
if [[ ${!i:j:1} == "s" ]]; then
k=$((i+1))
if [ -e ${!k} ]; then
echo $(realpath ${!k})
fi
elif [[ ${!i:j:1} == "o" ]]; then
echo "Running script without output!"
fi
done
fi
done
I get the following error when i run ./test -so doc1
./tests2: line 13: syntax error near unexpected token `newline'
./tests2: line 13: ` done'
Can anyone help me understand what's wrong with my script?
getoptscommand in thebashman page.getoptsi'll check that out!