Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Mar 1st, 2005, 7:08 PM   #1
noleander
Newbie
 
Join Date: Mar 2005
Posts: 5
Rep Power: 0 noleander is on a distinguished road
How create variables to hold directory names on Windows?

I'm working on a PC running Windows XP. Using win-bash, but not CygWin. Having tremendous problems with spaces in folder names. Posted a question earlier today, and Ooble promptly replied with an excellent answer: Changing dirs works as long as you omit the drive ID:

bash> cd "C:\Program Files" # fails
bash> cd "\Program Files" # works

Thanks to Ooble. Next question: After typing "Program Files" the 40th time I'm thinking it is time to store the string "Program Files" in a string. I tried creating a variable and using it:

declare pf="\Program Files"
cd $pf

but this does not work because of the space in the folder name (it does work for folders without spaces in the name).

QUESTION: In bash on Windows, how can I store directory names (containing spaces) in variables so I can use them for "cd"?

Thanks in advance for any help,
neal
(unix programmer reluctantly shifting to PC)
noleander is offline   Reply With Quote
Old Mar 1st, 2005, 7:18 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Create a new environment variable called "PF", and refer to it by typing "%PF%":
set PF="\Program Files"
 cd %pf%
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 1st, 2005, 8:40 PM   #3
noleander
Newbie
 
Join Date: Mar 2005
Posts: 5
Rep Power: 0 noleander is on a distinguished road
Thanks for the tip, but it does not seem to work. When I type

set var="abc"

this does not create an env variable. That is, I do not see the variable "var" when I look at the env variables (using either "set" or "declare" to display them).

I _can_ create env variables with "declare", but that does not work for the "cd" command as I discussed earlier because of the embedded space issue.

A clue: when I have a valid env variable (containing a valid directory path), such as HOMEPATH, and I try

cd %HOMEPATH%

that fails with msg:

C:\Program Files\bash\bash.exe: %HOMEPATH%: No such file or directory

I'm sure I am missing something obvious.

neal
noleander is offline   Reply With Quote
Old Mar 2nd, 2005, 5:24 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
That's because HOMEPATH has the C:\ bit in it - you can't CD to that. Try typing the code I posted earlier - it should work (at least, it did when I tested it).
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 7th, 2005, 9:21 AM   #5
noleander
Newbie
 
Join Date: Mar 2005
Posts: 5
Rep Power: 0 noleander is on a distinguished road
I tried it again, and it still fails. Here is the log of my bash shell:


bash$ cd "/Program Files"
bash$ pwd
C:/Program Files
bash$ set pf="/Program Files"
bash$ cd %pf%
C:\Program Files\bash\bash.exe: %pf%: No such file or directory


Any help would be appreciated!
neal
noleander is offline   Reply With Quote
Old Mar 7th, 2005, 10:18 AM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Perhaps it just doesn't work in the bash shell...
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« 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




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

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