Bash – How to stop the shell interpolating

bashshellzsh

I'm writing a bit of Ruby for use on the command line, but the shell is interfering too much – is there a way to turn off interpolation for the entire line? I know I can escape certain characters, but I'm looking for a blanket ban.

For example, I've got the shell set not to add to history if it begins with a blank space.

Any help with this is much appreciated.


I don't think I made myself clear, my apologies. An example:

ruby -pi -e 'gsub(/(find)(this)/, "#{$1} #{$2}")'

The shell won't interpolate those $ numbers because it's wrapped in single quotes, but sometimes the code will need to include quotes. Ruby is quite helpful in this, you can use other special characters to change quotes but then it all starts getting a bit messy, and it won't be as straightforward as above. What I'd like is something more like:

%% ruby -pi -e 'gsub(/(find)(this)/, "#{$1} #{$2}")'

Where %% would turn off interpolation by the shell for the rest of the line.

Best Answer

How about using a function that will read from a prompt and then execute literally what you type in?

function f { read -p"> " c; $c; }

In use, it will look like:

$ f
> echo $var
$var