Vim:让和设置有什么区别?(Vim: What's the difference between let and set?)
在vim编辑器中
set
和set
什么区别?我一直在想,为什么他们都存在?
此外,我有兴趣听到它的历史背景。
What's the difference between
let
andset
in the vim editor?I've always wondered why both of them exist?
Also, I'd be interested to hear its historical background.
原文:https://stackoverflow.com/questions/9990219
最满意答案
你的shell中的重复&1(在我的目录中为5),并在subshell中使用&5(以便您将写入父shell的stdout(&1)):
exec 5>&1 FF=$(echo aaa|tee >(cat - >&5)) echo $FF
将打印aaa两次,一个是因为subshell中的回声,并且第二次打印变量的值。
在你的代码中:
exec 5>&1 VAR1=$(for i in {1..5}; do sleep 1; echo $i; done | tee >(cat - >&5)) # use the value of VAR1
Duplicate &1 in your shell (in my examle to 5) and use &5 in the subshell (so that you will write to stdout (&1) of the parent shell):
exec 5>&1 FF=$(echo aaa|tee >(cat - >&5)) echo $FF
Will print aaa two times, ones because of the echo in the subshell, and second time print the value of the variable.
In your code:
exec 5>&1 VAR1=$(for i in {1..5}; do sleep 1; echo $i; done | tee >(cat - >&5)) # use the value of VAR1
相关问答
更多-
执行:显示stdout“活”(Exec : display stdout “live”)[2022-08-26]
不要使用exec 。 使用一个EventEmmiter对象的spawn 。 然后,您可以听到stdout / stderr事件( spawn.stdout.on('data',callback..) )。 从NodeJS文档: var spawn = require('child_process').spawn, ls = spawn('ls', ['-lh', '/usr']); ls.stdout.on('data', function (data) { console.log('s ... -
经典的解决方案是在脚本的顶部添加这样的东西: test -z "$REXECED" && { REXECED=1 exec $0 "$@" 2>&1 | tee -a somefile; exit; } 你可能还喜欢: test -t 1 && { exec $0 "$@" 2>&1 | tee -a somefile; exit; } The classical solution is to add something like this at the top of the script: te ...
-
#include
#define my_fprintf(fp,...) do{fprintf(fp, __VA_ARGS__);fprintf(stdout, __VA_ARGS__);}while(0) int main(int argc, char **argv){ FILE *fp; fp=fopen("output.txt","w");//or filename from argv[1] my_fprintf(fp, "hello world b ... -
您可以使用exec和进程替换将脚本中的stdout和stderr发送到tee。 进程替换是一种基础,因此它不可移植,如果将bash称为/ bin / sh或使用--posix,则无法工作。 exec > >(tee foo.log) 2>&1 set -x # I want to capture every line that's executed too cat 'foo' echo 'bar' sleep 2 睡眠被添加到最后,因为控制台的输出将由发球台缓冲。 睡眠将有助于防止提示在输出完成之前返回 ...
-
bash:将stdout捕获到一个变量,但仍然显示在控制台中(Capture stdout to a variable but still display it in the console)[2023-06-29]
你的shell中的重复&1(在我的目录中为5),并在subshell中使用&5(以便您将写入父shell的stdout(&1)): exec 5>&1 FF=$(echo aaa|tee >(cat - >&5)) echo $FF 将打印aaa两次,一个是因为subshell中的回声,并且第二次打印变量的值。 在你的代码中: exec 5>&1 VAR1=$(for i in {1..5}; do sleep 1; echo $i; done | tee >(cat - >&5)) # use the ... -
设置stdout是一个合理的方法。 另一个是将其作为另一个过程来运行: import subprocess proc = subprocess.Popen(["python", "-c", "import writer; writer.write()"], stdout=subprocess.PIPE) out = proc.communicate()[0] print out.upper() Setting stdout is a reasonable way to do it. Another is ...
-
如何将STDERR捕获到bash变量中而不影响STDOUT?(How can I capture STDERR into bash variable and not affect STDOUT?)[2022-08-01]
$( )构造总是捕获stdout,但是你可以在文件描述符之间玩弄。 只需在{ }对管道进行分组,然后使用2>&1将组中的stderr重定向到标准输出: output=$( { /bin/pg_dump -c --if-exists --dbname=cfMaster -U cfMaster | /bin/gzip > ~cftvdun/dbbackups/cfMaster.tmp.sql.gz; } 2>&1 ) 如果您还想要标准输出(而不是将它发送到文件),它会变得更加复杂。 我认为在这种情况下,你必须 ... -
StdOut来自Windows GUI在控制台中显示但未记录(StdOut From Windows GUI Shows in Console But isn't Logged)[2023-07-16]
我使用start / b而不是start / wait启动,输出被重定向到文件。 I launched with start /b instead of start /wait and the output was redirected to a file. -
看起来这样的回答会非常宽泛,所以我会把它留给抽象的。 你需要在方法中放置可重用的逻辑。 你需要一个“游戏循环”或“输入循环”。 你需要了解变量并将它们传递给方法。 你也可能想引入一个Player类而不是各种变量来保存不同的值。 你的游戏循环可能看起来像这样: ConsoleKey input = null; do { var player = DoGameLogic(input, player); PrintGameInfo(player); input = ReadInput(pl ...
-
需要从Android捕获选择性STDOUT以在listview中显示(Need to Capture selective STDOUT from Android for display in listview)[2022-01-28]
经过我自己的研究和进一步讨论与tuProlog开发人员之后,我有一个解决这个问题的方法,我认为值得与这个社区分享... 该问题的整体背景是让任何 Prolog实现在“正确”Android上作为更有趣的应用程序(专家系统,游戏AI和自然语言接口)的基础架构,以后再开始。 最大的障碍是Prolog是一个基于“控制台”的解释环境 ,可以打印到STDOUT,虽然Android容忍控制台打印活动,但默认情况下它会将所有这些操作路由到/ dev / null。 因此,有两组问题需要解决: (1)是否有任何 Prolog ...