LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 09: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, 09: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, 09: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, 01:39 PM   #4
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
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-11-2006, 11:24 PM   #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 01:58 PM
Variables and escape characters? flobadon Programming 4 09-10-2005 04:34 PM
Escape Characters in linux shunraj Linux - Software 1 05-18-2004 03:21 PM
Handle escape characters in a string Helene Programming 7 05-01-2004 11:43 PM
escape characters not escaping BobNz Linux - Software 2 04-09-2004 03:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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