Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 15th, 2011, 9:59 PM   #1
joelcarlton
Newbie
 
Join Date: Sep 2011
Posts: 3
Rep Power: 0 joelcarlton is on a distinguished road
\ escaped space is not being preserved after variable

I am trying to put absolute paths into my script and folder/folder\ folder is not being preserved. /folder/folder folder is being returned.

Here is an example:

#!/bin/bash
clear
read -p "Enter the Absolute Path to Source File/Folder: " Source
read -p "Enter the Absolute Path to Destination File/Folder: " Destination
echo "Usage: ln -vs $Source $Destination"
ln -vs $Source $Destination
cd $Destination; cd ..
ls -lasS


Does anyone know how to get the \ escape the be there after being put into a variable?

Thanks,
Joel
joelcarlton is offline   Reply With Quote
Old Sep 15th, 2011, 11:40 PM   #2
Patsie
Professional Programmer
 
Patsie's Avatar
 
Join Date: Jun 2010
Posts: 450
Rep Power: 5 Patsie is on a distinguished road
Re: \ escaped space is not being preserved after variable

cross site posting is not very nice

Last edited by Patsie; Sep 15th, 2011 at 11:52 PM.
Patsie is offline   Reply With Quote
Old Sep 15th, 2011, 11:52 PM   #3
joelcarlton
Newbie
 
Join Date: Sep 2011
Posts: 3
Rep Power: 0 joelcarlton is on a distinguished road
Re: \ escaped space is not being preserved after variable

Tried it, still doing same thing

I quoted my bash output below

#!/bin/bash
clear

read -p "Enter the Absolute Path to Source File/Folder: " "Source"
read -p "Enter the Absolute Path to Destination File/Folder: " "Destination"
echo "Usage: ln -vs $Source $Destination"
#ln -vs $Source $Destination
#cd $Destination; cd ..
#ls -lasS | grep $Destination


echo "$Source"
echo "$Destination"

Enter the Absolute Path to Source File/Folder: /Users/joel/Library/Application\ Support 
Enter the Absolute Path to Destination File/Folder: /Users/joel
Usage: ln -vs /Users/joel/Library/Application Support 
/Users/joel/Library/Application Support
/Users/joel
computer:~ joel$
joelcarlton is offline   Reply With Quote
Old Sep 16th, 2011, 10:58 AM   #4
joelcarlton
Newbie
 
Join Date: Sep 2011
Posts: 3
Rep Power: 0 joelcarlton is on a distinguished road
Re: \ escaped space is not being preserved after variable

I have it all worked out; see below

# Clear screen for input
clear
# Gather Source
read -p "Enter the Absolute Path to Source File/Folder: " Source
# replace spaces in Source variable with "\ "
Source2=$(echo $Source|sed -e 's| |\\ |g')
# Gather Destination
read -p "Enter the Absolute Path to Destination File/Folder: " Destination
# replace spaces in Destination variable with "\ "
Destination2=$(echo $Destination|sed -e 's| |\\ |g')

# Clear screen for output
clear
# Display current working directory
echo "Long listing taken from: `pwd`"
echo ""
# Execute command
eval ln -s $Source2 $Destination2
# cd to directory where link was created
eval cd $Destination2
# Extract the name of the link from the path of the 
# source file/folder turn that into a variable
greppath=$(echo $Source | rev | cut -d"/" -f1 | rev )
# Grep the name of variable just created and display
# it in a long listing showing the link
ls -lasS | grep "$greppath"
# Show Usage
echo "Usage: ln -vs $Source2 $Destination2"
echo ""
joelcarlton is offline   Reply With Quote
Reply

Bookmarks

Tags
bash, escape, variable

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Contents of a Variable for other Purposes than containing a Value Pluto C++ 5 Jan 30th, 2011 1:22 PM
spliting user space ashokraju07 JavaScript and Client-Side Browser Scripting 1 Dec 4th, 2010 11:48 AM
How to look ahead a variable number of lines .. EricFowler Sed and Awk 0 Aug 15th, 2009 9:37 PM
variable problem robert_sun C 1 Apr 12th, 2005 2:10 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC