variable.d 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  2. SPDX-License-Identifier: curl
  3. Long: variable
  4. Arg: <[%]name=text/@file>
  5. Help: Set variable
  6. Category: curl
  7. Example: --variable name=smith $URL
  8. Added: 8.3.0
  9. See-also: config
  10. Multi: append
  11. ---
  12. Set a variable with "name=content" or "name@file" (where "file" can be stdin
  13. if set to a single dash (-)). The name is a case sensitive identifier that
  14. must consist of no other letters than a-z, A-Z, 0-9 or underscore. The
  15. specified content is then associated with this identifier.
  16. Setting the same variable name again will overwrite the old contents with the
  17. new.
  18. The contents of a variable can be referenced in a later command line option
  19. when that option name is prefixed with "--expand-", and the name is used as
  20. "{{name}}" (without the quotes).
  21. --variable can import environment variables into the name space. Opt to either
  22. require the environment variable to be set or provide a default value for the
  23. variable in case it is not already set.
  24. --variable %name imports the variable called 'name' but exits with an error if
  25. that environment variable is not already set. To provide a default value if
  26. the environment variable is not set, use --variable %name=content or
  27. --variable %name@content. Note that on some systems - but not all -
  28. environment variables are case insensitive.
  29. When expanding variables, curl supports a set of functions that can make the
  30. variable contents more convenient to use. You apply a function to a variable
  31. expansion by adding a colon and then list the desired functions in a
  32. comma-separated list that is evaluated in a left-to-right order. Variable
  33. content holding null bytes that are not encoded when expanded, will cause
  34. error.
  35. Available functions:
  36. .RS
  37. .TP 15
  38. **trim**
  39. removes all leading and trailing white space.
  40. .TP
  41. **json**
  42. outputs the content using JSON string quoting rules.
  43. .TP
  44. **url**
  45. shows the content URL (percent) encoded.
  46. .TP
  47. **b64**
  48. expands the variable base64 encoded
  49. .RE
  50. .IP