Skip to main content
5 of 5
deleted 1 character in body
Jay jargot
  • 1.2k
  • 6
  • 9

Give a try to this standard and safe solution:

transfer() {
  printf -- "-F filedata=@%s\0" "$@" | xargs -0 sh -c 'curl --progress-bar -i "$@" https://transfer.sh | grep -i https' zerop
}

"$@" with the Double-Quotes will make the shell keeps the original options unchanged. See 2.5.2 Special Parameters section from The Open Group Base Specifications Issue 6:

@

Expands to the positional parameters, starting from one. When the expansion occurs within double-quotes, and where field splitting (see Field Splitting) is performed, each positional parameter shall expand as a separate field, with the provision that the expansion of the first parameter shall still be joined with the beginning part of the original word (assuming that the expanded parameter was embedded within a word), and the expansion of the last parameter shall still be joined with the last part of the original word. If there are no positional parameters, the expansion of '@' shall generate zero fields, even when '@' is double-quoted.

Using printf this way is a standard way to handle options. You may test it, and see that the result will be to generate as many -F filedata=@ strings as the number of options.

The test with 2 files having a special char in their names:

$ ls -b
f\ rst  s'cond

$ transfer() { printf -- "-F filedata=@%s\0" "$@" | xargs -0 sh -c 'curl --progress-bar -i "$@" https://transfer.sh | grep -i https' zerop ;}

$ transfer *
######################################################################## 100.0%
https://transfer.sh/fnzuh/f-rst
https://transfer.sh/fnzuh/scond
Jay jargot
  • 1.2k
  • 6
  • 9