1*6236dae4SAndroid Build Coastguard Worker<!-- Copyright (C) Daniel Stenberg, <[email protected]>, et al. --> 2*6236dae4SAndroid Build Coastguard Worker<!-- SPDX-License-Identifier: curl --> 3*6236dae4SAndroid Build Coastguard Worker# VARIABLES 4*6236dae4SAndroid Build Coastguard Workercurl supports command line variables (added in 8.3.0). Set variables with 5*6236dae4SAndroid Build Coastguard Worker--variable name=content or --variable name@file (where `file` can be stdin if 6*6236dae4SAndroid Build Coastguard Workerset to a single dash (-)). 7*6236dae4SAndroid Build Coastguard Worker 8*6236dae4SAndroid Build Coastguard WorkerVariable contents can be expanded in option parameters using `{{name}}` if the 9*6236dae4SAndroid Build Coastguard Workeroption name is prefixed with `--expand-`. This gets the contents of the 10*6236dae4SAndroid Build Coastguard Workervariable `name` inserted, or a blank if the name does not exist as a 11*6236dae4SAndroid Build Coastguard Workervariable. Insert `{{` verbatim in the string by prefixing it with a backslash, 12*6236dae4SAndroid Build Coastguard Workerlike `\{{`. 13*6236dae4SAndroid Build Coastguard Worker 14*6236dae4SAndroid Build Coastguard WorkerYou access and expand environment variables by first importing them. You 15*6236dae4SAndroid Build Coastguard Workerselect to either require the environment variable to be set or you can provide 16*6236dae4SAndroid Build Coastguard Workera default value in case it is not already set. Plain `--variable %name` 17*6236dae4SAndroid Build Coastguard Workerimports the variable called `name` but exits with an error if that environment 18*6236dae4SAndroid Build Coastguard Workervariable is not already set. To provide a default value if it is not set, use 19*6236dae4SAndroid Build Coastguard Worker`--variable %name=content` or `--variable %name@content`. 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard WorkerExample. Get the USER environment variable into the URL, fail if USER is not 22*6236dae4SAndroid Build Coastguard Workerset: 23*6236dae4SAndroid Build Coastguard Worker 24*6236dae4SAndroid Build Coastguard Worker --variable '%USER' 25*6236dae4SAndroid Build Coastguard Worker --expand-url = "https://example.com/api/{{USER}}/method" 26*6236dae4SAndroid Build Coastguard Worker 27*6236dae4SAndroid Build Coastguard WorkerWhen expanding variables, curl supports a set of functions that can make the 28*6236dae4SAndroid Build Coastguard Workervariable contents more convenient to use. It can trim leading and trailing 29*6236dae4SAndroid Build Coastguard Workerwhite space with `trim`, it can output the contents as a JSON quoted string 30*6236dae4SAndroid Build Coastguard Workerwith `json`, URL encode the string with `url` or base64 encode it with `b64`. 31*6236dae4SAndroid Build Coastguard WorkerTo apply functions to a variable expansion, add them colon separated to the 32*6236dae4SAndroid Build Coastguard Workerright side of the variable. Variable content holding null bytes that are not 33*6236dae4SAndroid Build Coastguard Workerencoded when expanded cause error. 34*6236dae4SAndroid Build Coastguard Worker 35*6236dae4SAndroid Build Coastguard WorkerExample: get the contents of a file called $HOME/.secret into a variable 36*6236dae4SAndroid Build Coastguard Workercalled "fix". Make sure that the content is trimmed and percent-encoded when 37*6236dae4SAndroid Build Coastguard Workersent as POST data: 38*6236dae4SAndroid Build Coastguard Worker 39*6236dae4SAndroid Build Coastguard Worker --variable %HOME 40*6236dae4SAndroid Build Coastguard Worker --expand-variable fix@{{HOME}}/.secret 41*6236dae4SAndroid Build Coastguard Worker --expand-data "{{fix:trim:url}}" 42*6236dae4SAndroid Build Coastguard Worker https://example.com/ 43*6236dae4SAndroid Build Coastguard Worker 44*6236dae4SAndroid Build Coastguard WorkerCommand line variables and expansions were added in 8.3.0. 45