bashcookiesenvironment-variableswget

Wget save cookies to bash environment variable


I know you can use wget to save cookies to a file

wget --save-cookies my-file.txt https://stackoverflow.com

is there a way to pipe --save-cookies straight to a bash environment variable?


Solution

  • You can write to /dev/stdout like that:

    $ cookies="$(wget --save-cookies /dev/stdout https://stackoverflow.com)"
    $ echo "$cookies"
    # HTTP cookie file.
    # Generated by Wget on 2022-01-24 17:59:48.
    # Edit at your own risk.
    
    .stackoverflow.com      TRUE    /       FALSE   2682374400      prov    0c002a59-7bf1-f8e9-2806-e50bb7e03a11