Error: /bin/bash: wget: command not found

17 次查看(过去 30 天)
Hello everyone,
I need to run a script that involves downloading a file one at a time from a list of urls, running the script, and this all done over a for-loop. I don't think I can use websave as I don't have a list of the file names, only the urls. This is the code I came up with:
urltxt=importdata("url.txt");
for r=1:length(urltxt)
urlname=urltxt{r};
%urlname=cell2mat(urlname);
!echo 'machine urs.earthdata.nasa.gov login <uid> password <pswd>' >> ~/.netrc
!chmod 0600 ~/.netrc
!wget --load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies --keep-session-cookies urlname
However, I keep getting the error: /bin/bash: wget: command not found. I have wget installed on my path and I'm able to run the code above in my terminal (OS). Any way to fix this?

回答(1 个)

Walter Roberson
Walter Roberson 2023-3-27
I have wget installed on my path
If you are using MacOS, then probably, NO, you do not have it installed on your path. Probably you used .bashrc or equivalent to add directories to your PATH environment variable. That will not work because programs that are launched using icons do not start login shells, and most of the shell initialization files are only processed for login shells.
In MacOS, you can use launchctl to add to your system PATH
Or you can add the executable to /usr/bin
Or you can set the path in your ! command, such as
!PATH=/usr/local/bin:$PATH wget --load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies --keep-session-cookies urlname
Or you can name the executable directly such as
!/usr/local/bin/wget --load-cookies ~/.urs_cookies --save-cookies ~/.urs_cookies --keep-session-cookies urlname

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by