fork download
  1. # generate something random to make an attacker's job harder
  2. pipe=$(uuidgen)
  3.  
  4. # use that randomly-generated sigil in place of | in our array
  5. cmd_array=(
  6. ls -a /
  7. "$pipe" grep "home"
  8. )
  9.  
  10. exec_array_pipe() {
  11. local arg cmd_q
  12. local -a cmd=( )
  13. while (( $# )); do
  14. arg=$1; shift
  15. if [[ $arg = "$pipe" ]]; then
  16. # log an eval-safe copy of what we're about to run
  17. printf -v cmd_q '%q ' "${cmd[@]}"
  18. echo "Starting pipeline component: $cmd_q" >&2
  19. # Recurse into a new copy of ourselves as a child process
  20. "${cmd[@]}" | exec_array_pipe "$@"
  21. return
  22. fi
  23. cmd+=( "$arg" )
  24. done
  25. printf -v cmd_q '%q ' "${cmd[@]}"
  26. echo "Starting pipeline component: $cmd_q" >&2
  27. "${cmd[@]}"
  28. }
  29.  
  30. exec_array_pipe "${cmd_array[@]}"
Success #stdin #stdout #stderr 0.01s 5272KB
stdin
Standard input is empty
stdout
home
stderr
Starting pipeline component: ls -a / 
Starting pipeline component: grep home