Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / October 2005



Tip: Looking for answers? Try searching our database.

Replacing whitespace, using bash script and sed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Neil Clayton - 10 Oct 2005 12:08 GMT
Hi All,
I'm writing a script to start an application, which begins by doing
this:

#!/bin/sh
BASEDIR=`dirname "$0"`
BASEDIR=`echo $BASEDIR | sed -e 's/ /\\ /g'`
echo Got $BASEDIR

If I simulate what is going to happen (it's going to be started by a
.app) using the following from the Terminal, I get:

sh /Users/neil/Development/planb/build/dist/mac/PlanB\
Console.app/Contents/MacOS/planbconsole
Got /Users/neil/Development/planb/build/dist/mac/PlanB
Console.app/Contents/MacOS

Note that the Folder 'PlanB Console.app' has not been replaced with
'PlanB\ Console.app'.
Yet if I do the same sed command from the terminal, it works fine.

echo /Users/neil/Development/planb/build/dist/mac/PlanB
Console.app/Contents/MacOS | sed -e 's/ /\\ /g'
/Users/neil/Development/planb/build/dist/mac/PlanB\
Console.app/Contents/MacOS

Anyone got any clues?
matt neuburg - 10 Oct 2005 20:14 GMT
> Hi All,
> I'm writing a script to start an application, which begins by doing
[quoted text clipped - 23 lines]
>
> Anyone got any clues?

Why are you doing this at all? Just quote the pathname variable and let
interpolation happen. m.

Signature

matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/exec/obidos/ASIN/0596005571
Read TidBITS! It's free and smart. http://www.tidbits.com

Doc O'Leary - 10 Oct 2005 23:48 GMT
> Anyone got any clues?

Stop doing "printf" debugging.  You're using echo twice in the script
but only once in Terminal.  What should be important is what is in
BASEDIR, not what it prints as.  Regardless, to get what you want, you'd
use:

echo Got "$BASEDIR"
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.