LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-08-2009, 11:20 PM   #1
Techno Guy
Member
 
Registered: Dec 2008
Posts: 53

Rep: Reputation: 15
How do you echo the folder name your currently in (using SHELL)?


Hi,

Im trying to find out how I can show what folder im currently in shell.

I had a little go with "ls" but could only get it to show all folders, not just the one im in.

Any help with this would be great
 
Old 03-08-2009, 11:26 PM   #2
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
You can use pwd command.
 
Old 03-08-2009, 11:28 PM   #3
Techno Guy
Member
 
Registered: Dec 2008
Posts: 53

Original Poster
Rep: Reputation: 15
Ah thanks alan_ri, your a legend
 
Old 03-08-2009, 11:58 PM   #4
Techno Guy
Member
 
Registered: Dec 2008
Posts: 53

Original Poster
Rep: Reputation: 15
Wait, no not quite what I wanted,

I was hoping for just the folder not the full path.

eg,
directory:

/home/users/TECHNO/

Output:
You are in the folder TECHNO
 
Old 03-09-2009, 01:52 AM   #5
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Type in the terminal:
Code:
export PS1="\W $ "
and hit <enter>.Now on the left side will be only the name of the directory you're currently working in,not the full path.I hope that this solution will be OK for you.
 
Old 03-09-2009, 01:57 AM   #6
Techno Guy
Member
 
Registered: Dec 2008
Posts: 53

Original Poster
Rep: Reputation: 15
No thats not what I wanted, I want to be able to have the folder name so I can use it in a echo script.


But don't worry I got a friend to help out.
This is what he/she gave to me (and it does what I wanted):
Code:
echo $PWD | sed -e "s#[^/]*/##g"
Thought id post it so anyone else ever looking as to how it's done can see
 
Old 03-09-2009, 02:13 AM   #7
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Sweet.
Well,you've showed us how it's done.
 
Old 03-09-2009, 03:14 AM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,838

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
This might be more readable to some ...
Code:
basename $(pwd)
 
Old 03-09-2009, 03:34 AM   #9
Techno Guy
Member
 
Registered: Dec 2008
Posts: 53

Original Poster
Rep: Reputation: 15
Oh nice, thats much cleaner, thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use single quote in bash shell like: echo ''\''' linuxtyh Linux - General 6 12-12-2008 12:56 AM
Bash shell file... echo on? carlos_vcan Linux - Newbie 3 06-12-2008 11:10 PM
cat, echo, & here documents in shell programming? ocicat Programming 4 09-17-2007 11:08 AM
can echo be used for popups in shell scripts run by cron? dr_zayus69 Linux - Software 4 04-12-2005 07:30 PM
crontabbed shell script, trying to echo/cat something zaubara Programming 2 06-13-2004 08:18 PM


All times are GMT -5. The time now is 02:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration