In Linux how can I fetch an URL and get its contents in a variable in shell script?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
wgetcommand to download the page and read it into a variable as:We use the
-Ooption ofwgetwhich allows us to specify the name of the file into whichwgetdumps the page contents. We specify-to get the dump onto standard output and collect that into the variablecontent. You can add the-qquiet option to turn off’s wget output.You can use the curl command for this aswell as:
We need to use the
-Loption as the page we are requesting might have moved. In which case we need to get the page from the new location. The-Lor--locationoption helps us with this.