Comment

Comment by mr-wendel

For all you Bash heads out there:

  DRYRUN=1
  VERBOSE=1
  
  cmd() {
      [ $DRYRUN -eq 1 -o $VERBOSE -eq 1 ] \
          && echo -e "\033[0;33;40m# $(printf "'%s' " "$@")\033[0;0m" >&2
      if [ $DRYRUN -eq 0 ]; then
          "$@"
      fi
  }
And now you can put this all over your scripts to very easily implement dry-run behavior without any quoting worries. Note that you can't invoke aliases this way.

  cmd echo "don't worry about quoting"
  cmd do_something_dangerous "$scary_arg" "$scary_arg2"
parent mr-wendel 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton