![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2011
Posts: 3
Rep Power: 0
![]() |
\ 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 |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jun 2010
Posts: 450
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Sep 2011
Posts: 3
Rep Power: 0
![]() |
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$ |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Sep 2011
Posts: 3
Rep Power: 0
![]() |
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 "" |
|
|
|
![]() |
| Bookmarks |
| Tags |
| bash, escape, variable |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |