Skip to content

Instantly share code, notes, and snippets.

@creeefs
Last active April 18, 2018 03:12
Show Gist options
  • Select an option

  • Save creeefs/c8448327f3c7dc5c8617b8e76abccf64 to your computer and use it in GitHub Desktop.

Select an option

Save creeefs/c8448327f3c7dc5c8617b8e76abccf64 to your computer and use it in GitHub Desktop.
#! /bin/bash
# Initially, I was trying to have my filter function return both the flag and the flag's values.
# As you can see below, my value substring contained spaces, which led to the following two outcomes:
# 1) If the command is not quoted, the shell parses the output and splits the string into 4 words
# 2) If the command is quoted, word splitting is avoided and you get 1 word
# In both cases, the ffmpeg utility would fail since it's not passed valid options.
filter_flag_and_value() {
echo "-filter_complex first second third"
}
filter_value() {
echo "first second third"
}
parameter_info() {
printf "Num args: %d\n" $#
printf "<%s> " "$@"
printf "\n"
}
# 4 positional parameters due to wordsplitting by the shell
parameter_info $(filter_flag_and_value)
# I don't think it's possible to have one function return both the flag and the value as 2 parameters.
parameter_info "$(filter_flag_and_value)"
# 2 positional parameters
parameter_info "-filter_complex" "first second third"
# 2 positional parameters since the result of the command substitution is not split thanks to the quotations
parameter_info "-filter_complex" "$(filter_value)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment