I created a text file with a command to install a dozen or so programs I want on any fresh install. I'd like to turn it into a script so that's the next thing I need to learn.
It sounds like you already have 99% of a script.
Turning it into a script is quite simple.
Assuming you have a text file like this:
PostInstallActions.txt
Code:
To install my preferred programs
from a fresh install use the command:
dnf install program1 program2 program3
First up add a shebang (#!) line at the top of the file that tells the shell which interpreter to use. So if you use bash you can add:
NOTE: This must be the very first line in the file.
Also, if you use a different shell you can specify it there - e.g. sh, zsh, csh etc etc.
Also, any lines of text that are not part of the command should be commented out using a # at the start of the line. So we should comment out the lines that contain our note to ourself.
So now we have a file that looks like this:
Code:
#!/bin/bash
# To install my preferred programs
# from a fresh install use the command:
dnf install program1 program2 program3
Alternatively, the commented out notes could be removed leaving us with:
Code:
#!/bin/bash
dnf install program1 program2 program3
Whatever you choose to do - now your text file is a valid shell-script.
The final task is to make it executable:
Code:
chmod +x PostInstallActions.txt
Optionally, you might also want to rename the script to lose the .txt extension, or rename it entirely:
Code:
mv ./PostInstallActions.txt mypostinstall.sh
Now we have a script called mypostinstall.sh which we can execute using:
You can back that up somewhere (on a USB stick) and then run it each time you do a fresh install on one of your PCs.
Job done! You've created your first simple script.
Edit:
There is a lot of other shell-scripting syntax for looping and branching and dealing with variables - allowing you to create much more complex scripts - I won't touch on that - I'll leave it to you to look into that.
There are a lot of websites and ebooks available that can help you to learn shell-scripting.
And there are several of us here who can help with any shell-scripting questions you might have along the way.
But for now, if you just want to run a sequence of simple commands in a script all you need to know is:
1. The first line must be a shebang line telling the shell which command interpreter to use
2. Comments always start with # - everything else is a command. Add any commands you want to run with some useful comments
3. Make the script executable
And that's about it at the simplest level.
I hope this was a useful start for you!