It was possible to solve the issue by using an array, as explained by @meuh. TheA solution forthat works in both bash and zsh is:
#!/usr/bin/env bash
transfer () {
push () {
if [[ args[${#args[*]}]="$1"
"$#" -eq 0 ]]; }then
build () {
echo "No arguments args=()specified."
forreturn file1
dofi
local -a args
push "-F"args=()
for file in "$@"
push "filedata=@$file"do
done
args+=("-F }filedata=@$file")
build "$@"done
curl --progress-bar -i "${args[@]}" https://transfer.sh | grep https
}
A similar approach can be taken withThe output in both zsh and bash is:
#!/usr/bin/env zsh
transfer ()$ {ls
local -atest args
space.txt args=()test'special.txt
$ fortransfer filetest\ inspace.txt "$@"test\'special.txt
######################################################################## do100.0%
args+="https://transfer.sh/z5R7y/test-F filedata=@$file"
donespace.txt
curl --progress-bar -i "${args[@]}" https://transfer.sh/z5R7y/testspecial.txt
$ |transfer grep*
######################################################################## 100.0%
https://transfer.sh/4GDQC/test-space.txt
}https://transfer.sh/4GDQC/testspecial.txt
The solution provided by @Jay also works perfectly well:
transfer() {
printf -- "-F filedata=@%s\0" "$@" \
| xargs -0 sh -c \
'curl --progress-bar -i "$@" https://transfer.sh | grep -i https' zerop
}