LinuxQuestions.org
Review your favorite Linux distribution.
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 07-11-2006, 10:34 AM   #1
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Rep: Reputation: 0
Paths and escape characters


I am using ubuntu, and I am writing a bash script. I am quite new to linux, and this is my first real script.

This script will run from the context menu in nautilus. I get the path of the current directory in the variable $NAUTILUS_SCRIPT_CURRENT_URI, and I need to strip off the last folder name. I use:
Code:
folder1=`basename "$NAUTILUS_SCRIPT_CURRENT_URI"`
or
Code:
folder1="${NAUTILUS_SCRIPT_CURRENT_URI##*/}"
and these work, so that if:
Code:
$NAUTILUS_SCRIPT_CURRENT_URI = home/this/that
then
Code:
$folder1 = that
...but if there are any spaces in the last folder, they show up as %20. How do I 'unescape' the spaces? I have tried:
Code:
folder2 = ${folder1//%20/\ }
But no dice. Any suggestions?
 
Old 07-11-2006, 10:45 AM   #2
hazmatt20
Member
 
Registered: Jan 2006
Distribution: FC5, Ubuntu
Posts: 126

Rep: Reputation: 15
What do you get if you try this?
Code:
$folder1 = that|sed 's/%20/\ /g'
 
Old 07-11-2006, 10:59 AM   #3
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Code:
album="${NAUTILUS_SCRIPT_CURRENT_URI##*/}"
$album = $album|sed 's/%20/\ /g'
kdialog --title "Album:" \
       --msgbox $album
Gives me the %20's. Any other suggestions? Am I doing something wrong?
 
Old 07-11-2006, 02:39 PM   #4
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
Maybe they are still spaces when you are handling them?
Try replacing them with underscores if that is an option:
Code:
$folder1 = that|sed 's#\ #_#g'
 
Old 07-12-2006, 12:24 AM   #5
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Original Poster
Rep: Reputation: 0
I got it working, although I don't really understand why.

Code:
a=`basename "$NAUTILUS_SCRIPT_CURRENT_URI"`
folder=${a//\%20/\ }
kdialog --title "folder:" \
       --msgbox "$folder"
Works, and the only difference I can see from my original attempt is that I wasn't escaping the '%', but I could have sworn that I did in 1 of the 1000 syntax permutations I tried.

Also, is there a problem with putting a space before the '='?

Thanks for the help.
 
  


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
passing escape characters along with lp command zita Linux - General 0 10-05-2005 02:58 PM
Variables and escape characters? flobadon Programming 4 09-10-2005 05:34 PM
Escape Characters in linux shunraj Linux - Software 1 05-18-2004 04:21 PM
Handle escape characters in a string Helene Programming 7 05-02-2004 12:43 AM
escape characters not escaping BobNz Linux - Software 2 04-09-2004 04:34 AM


All times are GMT -5. The time now is 05:18 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration