2

I am writing a script, located in ~/bin/ which is in my $PATH. I want to call this script from anywhere on the system (GNU/Linux, but this should not matter), and to read the current directory's contents.

Unfortunately, the script always reads the ~/bin/ contents, that is the place where the script itself is located.

Example:

  # pierre@autan: ~        < 2013_07_20__11_18_57 >
cat ~/bin/test.r 
#!/usr/bin/rebol
rebol []
print what-dir

  # pierre@autan: ~        < 2013_07_20__11_18_57 >
pwd
/home/pierre

  # pierre@autan: ~        < 2013_07_20__11_18_57 >
test.r
/home/pierre/bin/

The interpreter in /usr/bin/rebol is Rebol2/view. If I use a Rebol3, the result is the same, only it dereferences my ~/bin/ symlink:

  # pierre@autan: ~        < 2013_07_20__11_18_57 >
cat ~/bin/test.r 
#!/usr/bin/rebol3
rebol []
print what-dir

  # pierre@autan: ~        < 2013_07_20__11_18_57 >
test.r
/home/pierre/heaume_pierre/bin_scripts/

  # pierre@autan: ~        < 2013_07_20__11_18_57 >
ll | grep bin
lrwxrwxrwx  1 root   root         26 déc.  29  2010 bin -> heaume_pierre/bin_scripts/

Now, from the console, it works as expected:

  # pierre@autan: ~        < 2013_07_20__11_18_57 >
rebol
>> print what-dir 
/home/pierre/

I browsed through the documentation, but could not find anything helpful.

Does anyone know how to achieve this? Note that this is certainly a very common issue, for anyone who would like to write some kind of utility.

4

2 回答 2

4

Both in Rebol2 and Rebol3 system/options/path is your friend.

于 2013-07-20T09:49:25.977 回答
0

It now works as expected, after a change-dir to system/options/path:

  # pierre@autan: ~        < 2013_07_20__16_40_26 >
cat ~/bin/test.r 
#!/usr/bin/rebol3
rebol []
change-dir system/options/path
print what-dir

  # pierre@autan: ~        < 2013_07_20__16_40_26 >
test.r
/home/pierre/

I'll do this at the start of most of my scripts. Thanks, onetom!

于 2013-07-20T14:42:08.197 回答