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.