Johan
2007-05-22
Hi there
I'm writing a script to automate some repetitive tasks. The problem is, that the script uses the "cd" command a number of times (this is required, because of the workings of the script). Thus, when the script finishes, the command line is left in a different directory to the one from which it called the script.
The obvious solution is to store the working directory in a variable when the script starts, and then "cd" to that directory at the end of the script. However, I cannot seem to find a way to store the output of "pwd" in a variable. Can anyone help me? I am using Windows XP Pro with service pack 2.
Thanks
Johan
Peter Hochstrasser
2007-05-24
Johan
Without having tried it, the unix way to do this is:
$ set variable = ´command-to-execute´
$ export variable
note the forward acute ´ enclosing the command - this takes the return value of the command and assigns it to the variable.
The export statement makes the variable permanent/global; if you omit it, you can use it in your own script only.
P.
Johan
2007-05-24
Peter
You mean the character that shares a key with the tilde (~) on my keyboard? I.e. ASCII character decimal 96?
Thanks, but Windows doesn't seem to like that. Saying
C:\>set start_dir=`pwd`
gets interpreted literally, so that I can subsequently do:
C:\>set | grep start_dir
start_dir=`pwd`
It seems that the backtick isn't a special character in Windows.
Actually, it seems that using ' (ASCII decimal 39), doesn't work either.
Apart from that, your idea is exactly what I'm looking for.
Johan
Peter Hochstrasser
2007-05-25
;-)
Johan
Use the sh.exe as your shell that is delivered with the unxutils under the unxutils/bin directory. You'll see how things work...
P.
Peter Hochstrasser
2007-05-25
To be a bit more precise:
sh.exe actually starts the zsh included with the unxutils in the usr/local/wbin directory.
For your question above, go to the unxutils\bin directory (Windows path convention) and use the following little script:
sh
start_dir=`pwd`
echo 'variable start_dir='$start_dir
cd Desktop
cd ../WINDOWS/system
cd $start_dir
Hope that helps.
P.
Johan
2007-05-25
Peter
Thanks a million, I guess I should have expected a *nix shell in there.
I'm sure this will work.
Thanks again!
Johan