Register
It is currently Wed Dec 13, 2017 11:01 am

basename for directory variable


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Wed Dec 07, 2016 5:33 am   

Joined: Tue Apr 12, 2016 4:11 am
Posts: 51
hi all,

trying to get this to work but im struggling abit and wondered if you can help me out

basically i have created a variable

Code:
base='basename $dir'

echo "please specify full path to directory you want to be made into a tar"
                        read -e dir

tar -cf "$base".tar "$dir"


basically i want to strip the full path out and just leave what the directory is called

many thanks,

rob


Top
 Profile  
 PostPosted: Wed Dec 07, 2016 8:54 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
Quote:
dirname something


Top
 Profile  
 PostPosted: Wed Dec 07, 2016 9:13 am   

Joined: Tue Apr 12, 2016 4:11 am
Posts: 51
so can i do -
Code:
dirname=dirname $dir


Top
 Profile  
 PostPosted: Wed Dec 07, 2016 10:01 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
Yes, you can do.
But it does not what you want.

The first part is a variable assignment.
And the second part will throw an error as there is most likely no command named $dir

You want a substitution like
Code:
# the modern bash syntax
the_directory=$( dirname some/path/name )

# exactly the same but in ancient POSIX syntax
the_directory=`dirname some/path/name`

# use modern syntax, if shebang points to bash


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP