![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 5
Rep Power: 0
![]() |
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) |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Create a new environment variable called "PF", and refer to it by typing "%PF%":
set PF="\Program Files" cd %pf% |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Posts: 5
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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).
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2005
Posts: 5
Rep Power: 0
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|