bubblegumpi wrote:OK so I started this one but it still seems like its missing what some of the things do. Like it just jumps into the commands.
How did you guys learn? Thing is I'm legally blind so please don't just tell me to "google it". That doesn't help. .
One of the problems with googling it is that you'll often ask for how to do something in bash and get back how to do it in awk or grep or sed. If I wanted to know how to do it in awk or grep or sed, I'd have googled that. This is just something you have to put up with, like how you have to put up with asking for how to do something in python 3 and getting back how to do it in python 2.7. Grrrr.
A skeleton of a bash program, which could be done in a lot of different ways, is a good idea to start: For example:
Code: Select all
#!/bin/bash <-- this tells the system what program to run your script with
# these are comments
STRING="Hello World"
echo "First string: $STRING"
sleep 3s
echo "Delayed string $STRING"
But if your program is at all getting large or even just a bit unwieldy, you should look into using functions. Of course bash has them but its very weird:
Code: Select all
#!/bin/bash
echo_function(){
STRING="Hello World"
echo "First string: $STRING"
sleep 3s
echo "Delayed string $STRING"
}
echo_function # this should print one line and wait and print the second
echo "Next call:"
RETURN_STRING=$( echo_function )
printf "All of the lines are printed at once,\nthe pause is inside"
printf " the function: \n${RETURN_STRING}\n"
Mostly try to use echo for your debugging, so you can grep and make sure you've found them all. Use printf for real screen prints that you are going to leave in your program, it is a more standardised way to output text. You'll find echo used everywhere though, it just can cause problems since different versions of bash and shells operate with it in slightly different ways.
You'll also want to keep a cheat sheet with the exact crazy form of various things in bash, if it needs or doesn't need quotes on variables, if it needs or doesn't need spaces after itself, like the [ ] and [[ ]] commands, the if statement, etc. Numbers are also bizarre in bash, I think there's about six different ways to add one to a variable. Bash is very powerful, so no matter how mad you get at the craziness, it's worth taking a break and coming back to. Good luck, I'm sure people around here will help as needed.