DOWNLOAD_PATH="sample.ext"
RATE_LIMIT="300K"
mkdir ../$DOWNLOAD_PATH
BASE_COMMAND="screen wget --continue --directory-prefix=../$DOWNLOAD_PATH --tries=2 --input-file=$DOWNLOAD_PATH"
$("${BASE_COMMAND} --limit-rate=${RATE_LIMIT}")
This does not work, but throws an error:
line 5: screen wget --continue --directory-prefix=../sample.ext --tries=2 --input-file=sample.ext --limit-rate=300K: No such file or directory
However, if i do
DOWNLOAD_PATH="sample.ext"
RATE_LIMIT="300K"
mkdir ../$DOWNLOAD_PATH
BASE_COMMAND="screen wget --continue --directory-prefix=../$DOWNLOAD_PATH --tries=2 --input-file=$DOWNLOAD_PATH"
COMPLETE_COMMAND="${BASE_COMMAND} --limit-rate=${RATE_LIMIT}"
$($COMPLETE_COMMAND)
everything works just fine…
Why?
Because when you put
"${BASE_COMMAND} --limit-rate=${RATE_LIMIT}"in quotes, bash interprets it as a single word and tries to find a command with that name. It’s looking for a program that literally has the namespaces and all. Obviously that doesn’t exist. The solution is to leave that unquoted, so bash will interpret it as a list of space-separated words and understand that the command itself is just
screen.By the way, there’s no need to use
$()either unless you’re trying to capture the output of the command. This would be fine: