0

I don't want to access the shell command history in shell. It has to block for temporary purpose and after that I am able to release that block.

e.g. when I press up arrow in shell it shows the last command present in history, But i don't want to access history when I press up arrow on shell

Can we block history from accessing it?

i have tried set +o history but its for different purpose.

shell:> ifconfig
shell:> #some shell.py
Login: #when I press up arrow, "ifconfig" comes here as that was last command
Password:

for Login: it only has to access input, don't access history here. After accepting Login and Password then i can able to access history again.

  • Don't use [`readline`](https://cnswww.cns.cwru.edu/php/chet/readline/rltop.html) in `shell.py` (or start with a clean readline history) – hek2mgl Jul 06 '17 at 08:56
  • i can't use `clean history` , it will delete all history of current session. I have to use history again after blocking it temporary @hek2mgl –  Jul 06 '17 at 08:58
  • 1
    Is this really a question about [bash] and [shell], or it is a question about [python] and [readline]? – gboffi Jul 06 '17 at 09:08
  • [bash] and [shell] @gboffi , any doubt ?? –  Jul 06 '17 at 09:16
  • Yes, I doubt it. You should fix that problem on Python side – hek2mgl Jul 06 '17 at 09:40
  • How??? @hek2mgl –  Jul 06 '17 at 09:48
  • it is a question about [python] and [readline]? you were right @gboffi –  Jul 06 '17 at 10:18
  • I don't exactly how atm. If I'll find time today I'll have a look at this – hek2mgl Jul 06 '17 at 10:35
  • ok no problem @hek2mgl –  Jul 06 '17 at 11:21
  • 1
    Who wrote `shell.py`? You or a third party? Do you have access to its source code? — Imho the problem is in `shell.py` that misuse the readline library to read the user name and their password. The user name should be read using, simply, `input` and the password should be read using the [`getpass`](https://docs.python.org/3.6/library/getpass.html#module-getpass) module from the Python standard library – gboffi Jul 06 '17 at 21:51
  • yes for username we have read by using `raw_input` and password by using `getpass` @gboffi , still its not working –  Jul 07 '17 at 01:23
  • Can you show the most basic example of Python code which you are using? That's necessary to reproduce the problem – hek2mgl Jul 08 '17 at 09:16

2 Answers2

0

You can disable the Up Arrow Key by editing your ~/.bashrc and adding :

bind '"\e[A": '

Meaning : Bind Up Arrow Key to nothing

(You will need to reload it or re-open your session)

To re-enable it, simply remove the line and reload the .bashrc file

Esteban
  • 1,752
  • 1
  • 8
  • 17
0

To remove up-arrow binding

bind -r '\e[A'

To restore

bind '"\e[A": previous-history'

To retrieve all bindings to previous-history

bind -p | grep previous-history

or

bind -q previous-history

see also

help bind
Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36