Linux – Disable the “>” operator in Rstudio linux terminal

bashlinuxrstudiosshterminal

For an interactive session via SSH on a Linux cluster in Rstudio, it is very easy to accidentally execute the keyboard shortcut for "run in terminal" when commands are highlighted in Rstudio console. This results in behavior such as

\> library

or

Var1>Var2

being executed in terminal, which creates a library or Var2 file in the remote working directory if the terminal is logged in at the bash prompt.

In a worst case scenario this would result in overwriting files in the remote working directory.

I would like to disable ">" in these sessions, but I am not sure how to do this.

Best Answer

> is not a command but an operator for redirecting streams, so you can't alias it. But you can disable overwriting files with the noclobber option. Just run set -C or set -o noclobber (or add them to your ~/.bashrc)

The noclobber option is available to avoid overwriting existing files with output redirection (see The Set Builtin). The ‘>|’ redirection operator may be used to override noclobber.

If the file didn't exist it'll still be created, but at least you can avoid the worst case scenario. But you may still have problem if there are >| in your code

If you want to completely disable the redirection, you have to use the restricted shell but that'd result in an extremely limited environment, most notably you can't run commands with slashes like /bin/ls or change the directory

The best solution is to change the "run in terminal" shortcut in RStudio which was explain clearly in their website

Related Question