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.

  • heartlessevil@lemmy.one
    link
    fedilink
    English
    arrow-up
    6
    ·
    edit-2
    1 year ago

    I agree that’s probably the best you can do, but if it just printing the statements it sees and not actually running them, the behavior when it is run could be very different. For example:

    touch a_file
    if test -f a_file; then 
      rm -rf / 
    fi
    

    To do what OP is asking for would require running inside a sandbox.

    • RandomLegend [He/Him]@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      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.