I am making a small automation to add all the .java files in my current directory but it has some flaws.
It pushes each file instead of pushing them all at once, it's okay If it asks the commit message for each file but I tried to git push the files outside the for loop.
#!/bin/bash
javafile=*.java
for i in $javafile;
do
if [[ "$i" == "$javafile" ]]
then
echo "No .java files"
else
git add $i
echo
echo "File $i added"
echo
echo "Write a message to commit"
read message
git commit -m "$message"
git push origin master
echo
echo "#############################################"
echo "$i pushed successfully"
echo "#############################################"
fi
done
read -r messagenot justread message; as it is, any backslashes in your message will be destroyed.git push origin masteris inside the loop, but you aren't showing us how you tried to take it out of the loop, or what problem you had when doing that; so it's not clear what you're actually asking here. Why doesn't the most obvious solution (deleting the line from where it is now, and re-adding it at the end of the file) work for you?