I'm trying to write a bash file which normally takes 3 arguments normally. There is an extra condition which is invoked when there are more than 3 arguments given. This condition should export the extra arguments to a text file called excess. This is the code I have so far:
if [ $# -gt 3]; then
for ((i = 4; i <= $#; i++)); do
echo "$i" >> "excess.txt"
done
fi
Instead of exporting the actual arguments, the loop is exporting the numbers 4,5,6... to the text file.
I'm not quite sure why this is happening seeing that I've used the dollar sign before 'i' in the echo statement.