Given a url how to get last part of file

HI,

I have a URL that points to a file:

LINK= "http://www.webpage.org/project/team2/file.tar"

However when I try to use wget on this variable I receive the following error.

wget $LINK

line 4:   http://www.webpage.org/project/team2/file.tar: No such file or directory
wget: missing URL

The only way I can avoid the error is if I use wget against the URL directly

wget  http://www.webpage.org/project/team2/file.tar 

What I want to be able to do is two things:

  1. Take a URL and use wget against it
  2. Take the same URL and get the filename from it which in this case would mean printing "file.tar"

The reason that I mention the error is because I want to be able to assign the URL to a variable so I can use it in both cases because I do not want to have to input it twice.

Thanks!

LINK= "http://www.webpage.org/project/team2/file.tar"

There is an extra space in that.

LINK="http://www.webpage.org/project/team2/file.tar"

1 Like