This is an example of what I meant by comments which I think everyone should use for a few reasons.
#required for this type of bash script
echo “Please enter your username” #prints on screen asking user what their username is
read NAME #variable is NAME #reads user input
if [ “$NAME” = “bugs” ]; # if you’re username is bugs
then #then we do this
echo “Whats up doc” #if you don’t need to use an else the if ends after this line with fi
else #if it is not bugs we do this
echo “Invalid username exiting script”
fi # closes if statement
EDIT:I take no credit for this code it is from Hackersploits shell scripting tutorial series on youtube.
Very sorry for forgetting to give credit,
The # or / or something similar usually comments out a line so that you can put in comments in code that way it doesn’t try to run some imaginary function or whatever and give you errors.
So this asks you for your username and then IF it is X it will THEN it does something like this one prints on the screen Whats up doc(haha I always put silly things in when I am learning something).
And if you’re name isn’t X (ELSE) it will say “invalid username” and the script exits.
The FI is to close the IF statement.
Not sure if that helps but you can sort of see why comments might be important.
Not only do they help people understand what the code is doing it also helps me.
Say I don’t do any scripting for a year and I have forgotten a few things.
When I look at this code it helps remind me what it does,
I had this problem once because I didn’t use comments and it took me a few hours to look up what each script I had saved did when I could have commented it in the first place and spent less time remembering,
Anyway like I said I don’t know a lot just a little but I hope this helped you at least some.