Guest User

Untitled

a guest
Apr 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. # Initially, I was trying to have my filter function return both the flag and the flag's values.
  4. # As you can see below, my value substring contained spaces, which led to the following two outcomes:
  5. # 1) If the command is not quoted, the shell parses the output and splits the string into 4 words
  6. # 2) If the command is quoted, word splitting is avoided and you get 1 word
  7. # In both cases, the ffmpeg utility would fail since it's not passed valid options.
  8. filter_flag_and_value() {
  9. echo "-filter_complex first second third"
  10. }
  11.  
  12. filter_value() {
  13. echo "first second third"
  14. }
  15.  
  16. parameter_info() {
  17. printf "Num args: %d\n" $#
  18. printf "<%s> " "$@"
  19. printf "\n"
  20. }
  21.  
  22. # 4 positional parameters due to wordsplitting by the shell
  23. parameter_info $(filter_flag_and_value)
  24.  
  25. # I don't think it's possible to have one function return both the flag and the value as 2 parameters.
  26. parameter_info "$(filter_flag_and_value)"
  27.  
  28. # 2 positional parameters
  29. parameter_info "-filter_complex" "first second third"
  30. # 2 positional parameters since the result of the command substitution is not split thanks to the quotations
  31. parameter_info "-filter_complex" "$(filter_value)"
Add Comment
Please, Sign In to add comment