For example, if you have a file consisting of a and b characters. Your normal script replaces a with b. How do you reverse that? It's not possible to know original a's had been.
That maybe possible or impossible depending on the specific task. But there's hardly a generic way to do this.
If the task is about manipulating files you may take a backup before the task via cp, tar, rsync, ... and reset the state to that backup when needed.
What are you about to do? Why do want to reverse an action? What exactly do you want to reverse?
And of course: What's your OS environment and programming language/shell?
What are you about to do? Why do want to reverse an action?
Simple:
I want to have a second script that is not simply a "line by line reverse copy" of the first script,
but rather something that reads from the first.
=> So I don't have to have update two scripts.
Example:
TL;DR:
I want to have a script that parses another script and does the job in another order.
I want to have a script that parses another script and does the job in another order.
I would not say this isn't possible, but extremely complex to parse any scripting language or shell. I wouldn't ever dare to start such a program even having 20+ years of experience in scripting.
You need to have the skill level of a compiler/interpreter developer. Definitively not a practical way to go.
An option i got to know of are snaphotting tools: Run some programm. Look what it did(changed files, permissions,...) and undo the effects made.
Besides: We're at unix.com here. I doubt that you find much ms windows expertise here.
and pipe the result into sh . Be aware that when "automating" things you should know exactly what you are doing , and do a test run before each "live" run...