LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-22-2009, 05:48 AM   #1
Cyberman
Member
 
Registered: Aug 2005
Distribution: Debian Stable
Posts: 218

Rep: Reputation: 17
Basename and spaces: Directory has a space in its name


Directory:

/home/foo/bar bar/something

Code:
#!/bin/sh
UDIRX=`pwd`
BASENAME=$(basename $UDIRX)
echo
echo Object being worked on is $BASENAME.example
output: Object being worked on is bar.example

Code:
person@linux:~/bar bar/something$ basename `pwd`
bar

I don't want the output to be "bar."
How do I change the first script so that the output is something.example?
Is there a way I could have a script that works with directories that do and do not have a space?
 
Old 03-22-2009, 05:54 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Cyberman View Post
Directory:

/home/foo/bar bar/something

Code:
#!/bin/sh
UDIRX=`pwd`
BASENAME=$(basename $UDIRX)
echo
echo Object being worked on is $BASENAME.example
output: Object being worked on is bar.example

Code:
person@linux:~/bar bar/something$ basename `pwd`
bar

I don't want the output to be "bar."
How do I change the first script so that the output is something.example?
Is there a way I could have a script that works with directories that do and do not have a space?
Look at this:

Code:
basename "/home/foo/bar bar"
bar bar
and try to replace your

Code:
basename `pwd`
with

Code:
basename "`pwd`"
 
  


Reply



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
What is the unix command to trim multiple spaces into single space? manohare Linux - General 4 03-02-2009 07:25 AM
How do i change spaces inside a txt file, and replace space with backslash \? repolona Linux - Newbie 1 05-24-2006 05:08 AM
directory-names with spaces... Schmurff Linux - Newbie 2 03-07-2004 11:06 AM
BASH scripting problem, spaces in filenames / using basename textures Programming 24 11-16-2003 01:41 AM
cd to a directory with spaces? GT_Onizuka Linux - Newbie 3 08-28-2003 05:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:05 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
Open Source Consulting | Domain Registration