How to use "wget" command in Linux?
6 views (last 30 days)
Show older comments
MathWorks Support Team
on 1 Feb 2021
Commented: Walter Roberson
on 31 Jan 2025
I'm trying to run a program that needs to access the "wget" the command as follows:
[result, cmdout] = system('wget -h');
Do you have any suggestions to get it working in Linux?
Accepted Answer
MathWorks Support Team
on 24 Jan 2025
Edited: MathWorks Support Team
on 31 Jan 2025
You can call the “wget” command from MATLAB using the bang (!) operator:
The exclamation point character (!), sometimes called bang, is a shell escape. The character indicates that the rest of the input line is a command to the operating system. Use it to invoke utilities or call other executable programs without quitting MATLAB. To use the exclamation point in a factorial expression, call the factorial function. For example:
>> !wget --content-disposition "<url>"
This will execute the “wget” command as a system command from MATLAB.
Other possible workarounds for using "wget" are as follows:
1) Use the command “web”:
>> web('<url>');
However, it will open a dialog box and will ask you to save. It will require user interaction.
For more information on the function “web”, you can access the release-specific documentation by running the following command in MATLAB R2020b:
>> web(fullfile(docroot, 'matlab/ref/web.html'))
2) Use the command “websave”:
Give a name to the file and specify the type in which you want to save the data.
>> filename = ' eng-hourly-12012012-12312012.csv';
Create a variable named url and assign the URL to the variable from which you want to download the data.
>> url = 'http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&stationID=6358&Year=2012&Month=12&Day=14&timeframe=1&submit= Download+Data';
The “websave” function will save the data from the given URL to the specified file.
>> outputfilename = websave(filename,url);
For more information regarding the “websave” function, please follow the documentation link below:
Please follow the link below to search for the required information regarding the current release:
2 Comments
Walter Roberson
on 31 Jan 2025
If system('wget') fails, then !wget is not likely to work.
There is no documented difference between using system() and the ! operator.
It is true that the documentation for system() for Unix explicitly talks about looking at the MATLAB_SHELL and SHELL environment variables, and the documentation for the ! operator does not talk about either one of those. However, that does not prove that the ! operator is in any way different in operation -- it could just be weak documentation.
Walter Roberson
on 31 Jan 2025
More likely the problem is that wget does not happen to be on the search path.
When MATLAB is started from icon, it does not go through the login shell, so any shell environment setup of search paths is skipped. Only the sytem search path routinely assigned to daemons is available.
The fast work-around is to provide the path to the wget command when you system()
The intermediate work-around is to ensure that wget can be found by the system default path (for example putting a link to it in /usr/bin )
Finally, there are always options to add things to the system default search path; doing so might not be convenient at all.
More Answers (0)
See Also
Categories
Find more on Downloads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!