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.
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.
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
gets interpreted literally, so that I can subsequently do:
C:\>set | grep start_dir
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.
Use the sh.exe as your shell that is delivered with the unxutils under the unxutils/bin directory. You'll see how things work...
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:
echo 'variable start_dir='$start_dir
Hope that helps.
Thanks a million, I guess I should have expected a *nix shell in there.
I'm sure this will work.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.