This works:
TMPDIR="/tmp/___"
export TMPDIR
mkdir -p "$TMPDIR"
script="$TMPDIR"/myscript
cat <<'EOF' > "$script"
#!/usr/bin/Rscript --vanilla --slave
EOF
chmod 755 "$script"
ls -l "$script"
"$script"
ls -l "$script"
This removes $script
and files in /tmp
DO NOT RUN THIS IF YOU HAVE IMPORTANT STUFF IN /tmp
:
TMPDIR="/tmp/ "
export TMPDIR
mkdir -p "$TMPDIR"
script="$TMPDIR"/myscript
cat <<'EOF' > "$script"
#!/usr/bin/Rscript --vanilla --slave
EOF
chmod 755 "$script"
ls -l "$script"
"$script"
ls -l "$script"
The difference between these is only $TMPDIR
contains spaces.
What is the reason for this difference in behaviour?
$ Rscript --version
R scripting front-end version 4.1.2 (2021-11-01)
$ cat /etc/issue.net
Ubuntu 22.04.1 LTS
It looks more and more like a bug. If you compile R from source and set TMPDIR=" ":
:
make[3]: Entering directory '/tmp/R-devel/src/library/profile'
building system startup profile
make[3]: Leaving directory '/tmp/R-devel/src/library/profile'
make[3]: Entering directory '/tmp/R-devel/src/library/translations'
building package 'translations'
make[4]: Entering directory '/tmp/R-devel/src/library/translations'
make[4]: Leaving directory '/tmp/R-devel/src/library/translations'
make[3]: Leaving directory '/tmp/R-devel/src/library/translations'
make[3]: Entering directory '/tmp/R-devel/src/library/base'
building package 'base'
make[4]: Entering directory '/tmp/R-devel/src/library/base'
/bin/bash: line 9: /R3273656: No such file or directory
/bin/bash: line 12: /R23273656: No such file or directory
cmp: /R23273656: No such file or directory
mv: cannot stat ' /R23273656': No such file or directory
make[4]: *** [../../../share/make/basepkg.mk:65: mkRbase] Error 1
make[4]: Leaving directory '/tmp/R-devel/src/library/base'
make[3]: *** [Makefile:31: all] Error 2
make[3]: Leaving directory '/tmp/R-devel/src/library/base'
make[2]: *** [Makefile:37: R] Error 1
make[2]: Leaving directory '/tmp/R-devel/src/library'
make[1]: *** [Makefile:28: R] Error 1
make[1]: Leaving directory '/tmp/R-devel/src'
make: *** [Makefile:62: R] Error 1
Also changing TMPDIR in sysutils.c:1893 to DUMMY makes the issue go away.
/tmp
or some files? Only files? No directories? It looks like the only difference between the two cases is the value ofTMPDIR
and if it has trailing spaces, is that right or is there some other difference as well? It really helps if you point out the differences instead of making us try to find them since it is easy for us to miss something. – terdon Jan 25 '23 at 22:27/tmp
. What's worse, I get the exact same result if I simply runtouch "$TMPDIR"/myscript; Rscript "$TMPDIR"/myscript
. So givingRscript
an empty R script to run causes it to attempt to delete all files. – terdon Jan 25 '23 at 22:35Rscript
, no need for theRscript
shebang line, just runRscript whateverFile
and we get the same issue. It really feels like a bug inRscript
. – terdon Jan 27 '23 at 00:37