I wonder is there any program that can take a bash script as input and print out all bash commands it will run? A program that would unroll loops, expand environment variables and generally not perform any destructive action nor call any external binaries. It’s like a dry run of sorts.
- Found this over on Stackoverflow - You could try running the script under Kornshell. When you execute a script with - ksh -D, it reads the commands and checks them for syntax, but doesn’t execute them. Combine that with- set -xv, and you’ll print out the commands that will be executed.- You can also use - set -nfor the same effect. Kornshell and BASH are fairly compatible with each other. If it’s a pure Bourne shell script, both Kornshell and BASH will execute it pretty much the same.- You can also run - ksh -uwhich will cause unset shell variables to cause the script to fail. However, that wouldn’t have caught the catless cat of a nonexistent file. In that case, the shell variable was set. It was set to null.- Of course, you could run the script under a restricted shell too, but that’s probably not going to uninstall the package. - That’s the best you can probably do. - deleted by creator - yeah i think a sandbox would be the best solution. - Depending on what script OP is trying to run it would be best to just “rebuild” the potentially affected part of your system inside a VM and see what happens. 
 
- This is great—I’ve somehow never noticed - set -nbefore. Very helpful.
 
- It would depend. Bash allows for command substitution, so it’s possible that there are commands in a script where you would only know what they would do by running other lines in the script. - Edit: also, this is treading dangerously close to the Halting Problem. Imagine for a moment that you succeeded in creating such a program, written in Bash. Now imagine you gave this program its own source code as input. What would you expect it to tell you? - This is not close to the halting problem, it is harder than the halting problem. ;-) 
 



