I had a some difficulty myself with trying to get the current directory and
was convinced there was a bug in REBOL.
system/script/parent/path is the directory where rebol (or an auto-running
script) was invoked from the command line.
system/script/path is the directory what-dir returns and what change-dir
modifies. Note that this is used by clean-path to generate any relative
filenames. I expected what-dir, change-dir, and clean-path to operate on the
invocation directory (system/script/parent/path). This was an incorrect
assumption!
The trick seems to be calling 'change-dir system/script/parent/path' near the
start of the script to get 'normal' current directory behavior.
If there are associated scripts that live in the same directory as
the main script then do these before change-dir
(e.g. 'do join system/script/path %shared_data.r') or save system/script/path
for later use.
Below is the script I used to get a handle on what was happening. I made two
copies, one in the current shell directory named 'local_data.r' and another
someplace else named 'shared_tool' (as if it were a tool living in some bin or
command directory somewhere). Run 'rebol /path/to/shared_tool local_data.r', or
if you make it auto-executing then place it in your path and simply run
'shared_tool local_data.r'.
It just occured to me that perhaps REBOL is designed to be used primarily
inside of itself (using the interpreter as a shell and do-ing scripts from
inside it) rather than calling scripts from a host OS.
REBOL [
Purpose: {Test for understanding the REBOL path expressions.}
]
report-dir: func [] [
print [ "system/script/path:" system/script/path ]
print [ "system/script/parent/path:" system/script/parent/path ]
print [ "system/options/script:" system/options/script ]
print [ "what-dir:" what-dir ]
print [ "clean-path %bogusfile:" clean-path %bogusfile ]
print "^/"
]
report-dir
;print "change-dir system/script/parent/path^/["
;change-dir system/script/parent/path
;report-dir
;print "]^/"
print [ "system/script/args:" system/script/args ]
if string? system/script/args [
args: parse system/script/args none
forall args [
print rejoin [ "arg " index? args/1 ": " args/1 ]
print [ "clean-path" clean-path to-file args/1 "; <-- INVALID" ]
script: join system/script/parent/path args/1
print [ "Running script" script "^/" ]
do script
]
]
quit
;EOF
-Karl Robillard