[BASH] Remove Link from Filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [BASH] Remove Link from Filename
# 1  
Old 04-19-2009
[BASH] Remove Link from Filename

Hi there,


I'm trying to make a script that downloads something, but then strips the URL for later processing.


A user would input the following: ./text -install <link>

Lets say the <link> is: Later on, the script would have to; unpack the file with the command: tar xvf Program.tar.gz

But, it reads $2 as the full link


What I need done:

Remove everything up till the last / from $2



Thank you!
Have a good day!

Last edited by Syekiya; 04-19-2009 at 12:03 PM..
# 2  
Old 04-19-2009
Quote:
Originally Posted by Syekiya
What I need done:

Remove everything up till the last / from $2
Code:
basename $2

or

Code:
echo "$2" | sed 's!.*/!!'

Regards
# 3  
Old 04-19-2009
How would I set the basename into a variable?
# 4  
Old 04-19-2009
Code:
# link="http://unix.com/Program.tar.gz"
# echo ${link##*/}
Program.tar.gz

# 5  
Old 04-19-2009
store it in a variable


jarfile = `echo ${2##*/}`


cheers,
Devaraj Takhellambam
# 6  
Old 04-19-2009
Quote:
Originally Posted by devtakh
store it in a variable


jarfile = `echo ${2##*/}`


cheers,
Devaraj Takhellambam
no need echo
# 7  
Old 04-20-2009
If you are downloading the file using wget, then you can try the option -O and you can give your own name.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash to remove find and remove specific extension

The bash below executes and does find all the .bam files in each R_2019 folder. However set -x shows that the .bam extension only gets removed from one .bam file in each folder (appears to be the last in each). Why is it not removing the extension from each (this is $SAMPLE)? Thank you :). set... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. UNIX for Beginners Questions & Answers

Bash script - Remove the 3 top level of a full path filename

Hello. Source file are in : /a/b/c/d/e/f/g/some_file Destination is : /d/e where sub-directories "f" and "g" may missing or not. After copying I want /a/b/c/d/e/f/g/file1 in /d/e/f/g/file1 On source /a is top-level directory On destination /d is top-level directory I would like... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

Get the filename linked to symbolic link

Hello guys, I have a simple problem. Do you know any way to get the get the filename linked to symbolic link? I think use "ls -l <myfile> | cut -d '>' -f2", but i know it is a bad practice take information from the output of "ls -l". I dont have "stat" comand neither. :( Regards! ... (6 Replies)
Discussion started by: Xedrox
6 Replies

4. Red Hat

How to remove symbolic link?

this is my current code, # ln -s /lib64/ # ls -lrth total 80K -rw-r--r--. 1 root root 12K Jul 6 2012 post-install -rw-r--r--. 1 root root 552 Jul 6 2012 post-install.log -rw-------. 1 root root 1.5K Aug 21 2012 anaconda-ks.cfg drwxr-xr-x. 2 root root 4.0K Aug 21 2012 Videos... (3 Replies)
Discussion started by: jediwannabe
3 Replies

5. Shell Programming and Scripting

how to remove soft link

hi i have create a soft link using below command. ln -s <filename> <dirmane>where file name i use is t1 and dir name was t2. i deleted the dir t2 using command rm -rf to remove the soft link . however again i create a file a using the name t2 and when i just try to link t1 to t2 ... (1 Reply)
Discussion started by: scriptor
1 Replies

6. Solaris

How to remove soft link safely

Greetings, I need some help performing a system admin function that I have been tasked with. The request seems simple enough, but my feeling is that it might be more complicated than it seems. Here is what i've been tasked with: SunOS 5.10 Generic_142900-15 sun4u sparc SUNW,SPARC-Enterprise... (3 Replies)
Discussion started by: Harleyrci
3 Replies

7. Shell Programming and Scripting

how to remove the target of the symbol link in a shell script

I have a target directory, there are some files and directories in "target_dir". I have a symbol link: my_link -> <target_dir> The target directory name is NOT known to the script (because it is varying), while the link name is always fixed. In a shell script, how to remove both the... (1 Reply)
Discussion started by: princelinux
1 Replies

8. UNIX for Dummies Questions & Answers

Is there a way to completely remove an inode when the Link count is 2 ?

Currently my data is organised in a volume which has a cache directory (where all the files are first created or transferred). After that there are suitable directories on the volume which in their subdirs, contain files hardlinked to files in the cache. This is done so that the same inode... (1 Reply)
Discussion started by: abcdino
1 Replies

9. Shell Programming and Scripting

How to remove filename from the path

Hi, I have a list of paths with files at the end. How can strip off filenames. This is what I have: /apps/test/abc/file.txt /apps/new/home/daily/report.xml /apps/old/home/weekly/out/test.sh This is what I need: /apps/test/abc/ /apps/new/home/daily/ /apps/old/home/weekly/out/ ... (10 Replies)
Discussion started by: djanu
10 Replies

10. UNIX for Dummies Questions & Answers

Remove path from filename

In a foreach loop I end up with $file containing the filename INCLUDING the whole path. I want this reduced to just the filename, but I can't seem to remember how I did it some years back. I am sure I can do it with "sed", but I am pretty sure I have seen a simpler command. Anyone? borgeh (3 Replies)
Discussion started by: borgeh
3 Replies
Login or Register to Ask a Question