Is there a way to preprocess input to bash?

6

1

I would like to be able to define arbitrary modifications to command lines that happen before bash sees them at all, ie, before expansion of any kind. Is this possible?

I'm not trying to solve one particular problem, I'm really just curious if it is possible to obtain exactly this functionality without writing my own shell.

Personman

Posted 2010-07-24T20:30:07.733

Reputation: 273

What kind of modifications? If you just want shortcuts to things, use alias. – jtbandes – 2010-07-24T21:13:51.023

ockquote>

"before expansion of any kind."

I would like to do complete rewriting of entire command lines. Aliases and shell functions are the limitation I am trying to overcome. – Personman – 2010-07-24T21:28:47.577

Answers

2

I would suggest that you investigate the possibility of binding the readline function accept-line (Ctrl-m) into the Bash completion facility (readline complete) where you would be able to process the line and should be able to execute it from there.

Paused until further notice.

Posted 2010-07-24T20:30:07.733

Reputation: 86 075

Can you give an example of how one would do this? Are you suggesting using a bind command to change the behavior of C-m? Or are you suggesting that complete offers some way to intercept accept-line? – poindexter – 2012-04-27T18:03:43.573