./fortune.sh -f thing.txt -a -n 2
is the format, my code already checks to see if the "-f" , "-n" , "-a" , and the "2" (aka the fifth argument it can be any number to show how many times the for loop should loop) is present. But in my code, the output is that it asks me for an input once, and then prints out a random line from the text file. I need it to ask me for inputs (that are added on to the text file "thing.txt") for the amount of times the user put in; for example, it would ask for two inputs since the fifth argument is a "2"
I've tried using variables as place holders for what the arguments are for example: yah2=$5 userfile=$2
and for the part where it adds the inputs onto the file i did something like:
read -p "Enter a new fortune: " wisdom2
echo "$wisdom2" >> "$userfile"
it adds only one input and then shows me a random line from the file.
if [ "$1" = "-f" ] && [ "$3" = "-a" ] && [ "$4" = "-n" ]
then
yah2=$5
userfile=$2
for i in $yah2
do
read -p "Enter a new fortune: " wisdom2
echo "$wisdom2" >> "$userfile"
done
fi
As previously stated, the code needs to ask me for an input for how many times the fifth argument is. For example if $5 = 2 it would then be placed in the variable "yah2" so it would loop twice but it doesn't. I don't know if "echo" is doing the right job either.