When I'm debugging a script, I'll often take a line I'm not quite sure about e.g.:
hdiutil create -srcfolder "$3" -format UDRO -fs APFS -volname "$1" -ov "$2"
and simply change it to:
echo hdiutil create -srcfolder "$3" -format UDRO -fs APFS -volname "$1" -ov "$2"
Then when I run my script the first time, it won't run the (potentially incorrect) command but I can see it and check that it looks correct… and maybe even copy/paste it to run it manually.
But this isn't reliable/correct if any of the arguments have spaces in them. The echo shows spaces within an argument just the same as the separator between arguments.
I found the set -x command which helpfully logs every command with arguments properly escaped! That's what I'm using for now, but it's pretty broad-grained (noisy across a large script where I'm focused on just one line) and doesn't prevent the actual un-verified command from running.
Is there a quick/clean way to do this for just one line. Or some other trick using commonly available commands — maybe some combination of env and printf or whatnot? or a dedicated command that got included for basically this purpose?
Ideally it'd be something I could just pre-pend to the line in question which would both "comment it out" and show me exactly what it would have done if enabled.
set -xright before the line you're interested in, andset +xafter.set -xthen you could usebashdbwhich can be installed via MacPorts or Homebrew.