Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在shell中阻止命令历史访问_Python_Bash_Python 2.7_Shell_Readline - Fatal编程技术网

Python 在shell中阻止命令历史访问

Python 在shell中阻止命令历史访问,python,bash,python-2.7,shell,readline,Python,Bash,Python 2.7,Shell,Readline,我不想访问shell中的shell命令历史记录。它必须暂时阻塞,然后我才能释放该阻塞 例如当我在shell中按向上箭头时,它会显示历史记录中存在的最后一个命令,但当我在shell上按向上箭头时,我不想访问历史记录 我们可以阻止历史访问它吗 我尝试了set+o history,但目的不同 shell:> ifconfig shell:> #some shell.py Login: #when I press up arrow, "ifconfig" comes here as that

我不想访问shell中的shell命令历史记录。它必须暂时阻塞,然后我才能释放该阻塞

例如当我在shell中按
向上箭头时,它会显示历史记录中存在的最后一个命令,但当我在shell上按向上箭头时,我不想访问历史记录

我们可以阻止历史访问它吗

我尝试了
set+o history
,但目的不同

shell:> ifconfig
shell:> #some shell.py
Login: #when I press up arrow, "ifconfig" comes here as that was last command
Password:
对于登录:它只需要访问输入,不需要在此处访问历史记录。
接受登录和密码后,我可以再次访问历史记录。

您可以通过编辑
~/.bashrc
并添加以下内容来禁用向上箭头键:

bind'\e[A:'

含义:将
向上箭头键绑定为空

(您需要重新加载或重新打开会话)


要重新启用它,只需删除该行并重新加载
.bashrc
文件

即可删除向上箭头绑定

bind -r '\e[A'
恢复

bind '"\e[A": previous-history'
要检索到
以前历史记录的所有绑定

bind -p | grep previous-history

另见

help bind

不要在
shell.py
中使用(或者从一个干净的读线历史开始)我不能使用
clean history
,它将删除当前会话的所有历史记录。在临时阻止它之后,我必须再次使用历史记录@hek2mglIs这确实是关于[bash]和[shell]的问题,或者是关于[python]和[readline]?[bash]和[shell]的问题@GBOFI,有任何疑问吗?谁写了
shell.py
?你还是第三方?你有权访问它的源代码吗?-我想问题出在
shell.py
错误地使用readline库读取用户名和密码。用户名应该使用
input
读取,密码应该使用Python标准库中的模块它只阻止
向上箭头
,但当我们点击
ctrl+p
时,这将再次访问@nahuelfouillel的历史记录。您想阻止所有到上一个历史记录的绑定还是阻止最后一个命令添加到历史记录列表中?所有到上一个历史记录@nahuelfouillel的绑定都会出错为
/bin/sh:1:bind:not found
@NahuelFouilleul在与
subprocess.call()一起运行它时,我可以在
python shell中使用它吗
help bind