curl/docs/cmdline-opts/config.d

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.7 KiB
D
Raw Normal View History

c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
SPDX-License-Identifier: curl
Long: config
Arg: <file>
Help: Read config from a file
Short: K
Category: curl
Example: --config file.txt $URL
Added: 4.10
See-also: disable
Multi: append
---
Specify a text file to read curl arguments from. The command line arguments
found in the text file will be used as if they were provided on the command
line.
Options and their parameters must be specified on the same line in the file,
separated by whitespace, colon, or the equals sign. Long option names can
optionally be given in the config file without the initial double dashes and
if so, the colon or equals characters can be used as separators. If the option
is specified with one or two dashes, there can be no colon or equals character
between the option and its parameter.
tool: add "variable" support Add support for command line variables. Set variables with --variable name=content or --variable name@file (where "file" can be stdin if set to a single dash (-)). Variable content is expanded in option parameters using "{{name}}" (without the quotes) if the option name is prefixed with "--expand-". This gets the contents of the variable "name" inserted, or a blank if the name does not exist as a variable. Insert "{{" verbatim in the string by prefixing it with a backslash, like "\\{{". Import an environment variable with --variable %name. It makes curl exit with an error if the environment variable is not set. It can also rather get a default value if the variable does not exist, using =content or @file like shown above. Example: get the USER environment variable into the URL: --variable %USER --expand-url = "https://example.com/api/{{USER}}/method" When expanding variables, curl supports a set of functions that can make the variable contents more convenient to use. It can trim leading and trailing white space with "trim", output the contents as a JSON quoted string with "json", URL encode it with "url" and base 64 encode it with "b64". To apply functions to a variable expansion, add them colon separated to the right side of the variable. They are then performed in a left to right order. Example: get the contents of a file called $HOME/.secret into a variable called "fix". Make sure that the content is trimmed and percent-encoded sent as POST data: --variable %HOME=/home/default --expand-variable fix@{{HOME}}/.secret --expand-data "{{fix:trim:url}}" https://example.com/ Documented. Many new test cases. Co-brainstormed-by: Emanuele Torre Assisted-by: Jat Satiro Closes #11346
2023-07-31 17:50:28 +08:00
If the parameter contains whitespace or starts with a colon (:) or equals sign
(=), it must be specified enclosed within double quotes (\&"). Within double
quotes the following escape sequences are available: \\\\, \\", \\t, \\n, \\r
and \\v. A backslash preceding any other letter is ignored.
tool: add "variable" support Add support for command line variables. Set variables with --variable name=content or --variable name@file (where "file" can be stdin if set to a single dash (-)). Variable content is expanded in option parameters using "{{name}}" (without the quotes) if the option name is prefixed with "--expand-". This gets the contents of the variable "name" inserted, or a blank if the name does not exist as a variable. Insert "{{" verbatim in the string by prefixing it with a backslash, like "\\{{". Import an environment variable with --variable %name. It makes curl exit with an error if the environment variable is not set. It can also rather get a default value if the variable does not exist, using =content or @file like shown above. Example: get the USER environment variable into the URL: --variable %USER --expand-url = "https://example.com/api/{{USER}}/method" When expanding variables, curl supports a set of functions that can make the variable contents more convenient to use. It can trim leading and trailing white space with "trim", output the contents as a JSON quoted string with "json", URL encode it with "url" and base 64 encode it with "b64". To apply functions to a variable expansion, add them colon separated to the right side of the variable. They are then performed in a left to right order. Example: get the contents of a file called $HOME/.secret into a variable called "fix". Make sure that the content is trimmed and percent-encoded sent as POST data: --variable %HOME=/home/default --expand-variable fix@{{HOME}}/.secret --expand-data "{{fix:trim:url}}" https://example.com/ Documented. Many new test cases. Co-brainstormed-by: Emanuele Torre Assisted-by: Jat Satiro Closes #11346
2023-07-31 17:50:28 +08:00
If the first non-blank column of a config line is a '#' character, that line
will be treated as a comment.
Only write one option per physical line in the config file. A single line is
required to be no more than 10 megabytes (since 8.2.0).
Specify the filename to --config as '-' to make curl read the file from stdin.
Note that to be able to specify a URL in the config file, you need to specify
it using the --url option, and not by simply writing the URL on its own
line. So, it could look similar to this:
2020-11-04 21:02:01 +08:00
url = "https://curl.se/docs/"
# --- Example file ---
# this is a comment
url = "example.com"
output = "curlhere.html"
user-agent = "superagent/1.0"
# and fetch another URL too
url = "example.com/docs/manpage.html"
-O
referer = "http://nowhereatall.example.com/"
# --- End of example file ---
When curl is invoked, it (unless --disable is used) checks for a default
config file and uses it if found, even when --config is used. The default
config file is checked for in the following places in this order:
1) **"$CURL_HOME/.curlrc"**
2) **"$XDG_CONFIG_HOME/curlrc"** (Added in 7.73.0)
3) **"$HOME/.curlrc"**
4) Windows: **"%USERPROFILE%\\.curlrc"**
5) Windows: **"%APPDATA%\\.curlrc"**
6) Windows: **"%USERPROFILE%\\Application Data\\.curlrc"**
7) Non-Windows: use getpwuid to find the home directory
8) On Windows, if it finds no *.curlrc* file in the sequence described above, it
checks for one in the same dir the curl executable is placed.
On Windows two filenames are checked per location: *.curlrc* and *_curlrc*,
preferring the former. Older versions on Windows checked for *_curlrc* only.