You are not logged in.

#1 2012-03-07 03:14:53

maw09
Member
Registered: 2012-02-06
Posts: 9

[SOLVED] Can't bind Ctrl+J in bash

I'd like to bind Ctrl-J to a command in BASH, specifically I'd like to do this:

bind '"\C-j":"clear; ls *\n"'

But it seems that because Ctrl-J is the linefeed key, the escape sequence \n calls whatever Ctrl-J is bound to, so the result of pressing Ctrl-J is:

clear; ls *clear; ls *clear; ls *clear; ls *clear; ls * ...

Is there any way to bind Ctrl-J and retain the meaning of \n? Or is there an alternative to \n?

Last edited by maw09 (2012-03-07 03:23:23)

Offline

#2 2012-03-07 03:19:19

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [SOLVED] Can't bind Ctrl+J in bash

Presumably you want bind to be executing a command, not just inserting characters into the terminal's input buffer. You need to use the -x flag to bind.

bind -x '"\C-j":"clear;ls"'

Offline

#3 2012-03-07 03:21:44

maw09
Member
Registered: 2012-02-06
Posts: 9

Re: [SOLVED] Can't bind Ctrl+J in bash

Thanks that works perfectly!

Offline

Board footer

Powered by FluxBB