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.

2 Answers 2

4

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

2
  • Thanks. I'm still wondering why %. is not equivalent to system/options/path.
    – Pierre
    Commented Jul 20, 2013 at 11:35
  • 1
    I would be interested about that too. The bigger question for me though is how to avoid these kind of questions asked over and over again. How to represent such design decisions in an accessible way? The REBOL/Core User Manual has answered a lot of these kind of questions but it's a bit outdated... :/
    – onetom
    Commented Aug 8, 2013 at 0:18
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!

Not the answer you're looking for? Browse other questions tagged or ask your own question.