带有2& 1和命令提示符的意外重定向结果 [英] Unexpected redirect result with 2>&1 and command prompt
问题描述
我在玩nc,因为-e命令消失了,所以推荐
I was playing around with nc and since the -e command is gone, it recommended
cat /tmp/f | /bin/sh -i 2>&1 | nc -l 127.0.0.1 1234 > /tmp/f
我认为"2>& 1"是不必要的,因为我不需要知道我将要运行的简单命令(例如"whoami","ls"等)的错误,因此我的命令改为是
I thought that the "2>&1" is unnecessary because I don't need to know the errors of the simple commands I was going to run like "whoami", "ls", etc. so my command instead is
cat /tmp/f | /bin/sh -i | nc -l 127.0.0.1 1234 > /tmp/f
但是,然后,我没有得到干净"的结果.这就是我得到的
But then, I don't get "clean" results. This is what I get
服务器:
Listening on [0.0.0.0] (family 0, port 1234)
$ $
客户:
nc localhost 1234
ls
testfile
whoami
user1
基本上,我在客户终端中看不到$.当我对2>& 1执行命令时,我得到了期望的结果
Basically, I don't see the $ in my client terminal. When I do the command with the 2>&1, I get what I expected
服务器:
Listening on [0.0.0.0] (family 0, port 1234)
客户:
nc localhost 1234
$ ls
testfile
$ whoami
user1
我知道2>& 1表示将stderr重定向到stdout,因此在这种情况下,命令提示符"$"在stderr中如何?它不应该是stdin的一部分吗?
I know that 2>&1 means redirect stderr to stdout so in this case, how is the command prompt "$" part of the stderr? Shouldn't it be part of stdin?
推荐答案
shell使用标准错误流来显示提示,以及使用 select
和其他任何文本创建的菜单是为了与用户互动.
The shell uses the standard error stream for prompts, and also for menus created by select
, and any other text that is meant for interacting with the user.
这篇关于带有2& 1和命令提示符的意外重定向结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!