I have a problem. I have a batch file that mimics the cd UNIX command. It takes a UNIX-style path entered by the user, saves it as a var, called upath2, converts it to a Windows-style path, and cd into this directory (for example, "/ program files / 7-zip" will become "C: \ Program Files \ 7-Zip "). Windows-like output will be saved as a var command with the name upath2, and cmd cd will execute and change in this directory.
Along with this "UNIX" cd command, I also created a batch file called "bashemu.bat" that gives me a bash prompt. All commands are doskey entries that reference the bin and usr \ bin files I created that contain all the .bat commands. Then it runs "cmd / v / k" at the end, so that I can enter doskey aliases and run all of my UNIX-style commands.
Now here is my problem: when I cd-ing into a subdirectory of my folder C: \ Users \ xplinux557 (stored in an environment variable called "unixhome"), the bashemu hint changes from:
xplinux557@bash-pc :~$
eg:
xplinux557@bash-pc :/Users/xplinux557/Documents/MacSearch_v.1.4.3[1]/Skins/Blue/Icons$
Paths like these are too long to be conveniently used in bashemu on the command line, so I'm trying to get the cd command to read the full upath2 variable and check if it contains the home path (as defined by unixhome) and just replace it with ~. This should do the following:
xplinux557@bash-pc :/Users/xplinux557/Documents/MacSearch_v.1.4.3[1]/Skins/Blue/Icons$
in it:
xplinux557@bash-pc :~/Documents/MacSearch_v.1.4.3[1]/Skins/Blue/Icons$
Ahhh, much better! My first approach was to convert the UNIX-style path to Windows-Style and name the new var upath2 and replace the text% unixhome% with "~". So the code looked:
:: set the batch file to retrieve all text from its parameters and replace all :: unix-style slashes the user put in and replace those with a windows-style backslash @echo off set upath=%* set upath=%upath:/=\% :: cd to the directory that the user typed in, windows-style cd "%upath%" :: Set the upath2 var to the current directory and replace whatever unixhome was :: a "~" set upath2=%cd:%unixhome%="~"% :: Remove the "C:" or "D:" from the quote set upath2=%upath2:~2% :: then, set the prompt to read: :: " xplinux557@bash-pc :~/Documents/MacSearch_v.1.4.3[1]/Skins/Blue/Icons$" prompt=%USERNAME%@%USERDOMAIN%:%upath2% $$ ::EOF
Everything works fine, except for the line that says:
set upath2=%cd:%unixhome%="~"%
I understand this is a mess and recognizes% cd:% and% = "~"% as variables and gives me an error message. I really really regret that I am too much and so on :), but the long story is short, is there a way to take the text of variable A and replace this text if it is found in variable B?
Thank you all in advance!