问题标签 [backticks]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
298 浏览

powershell - 了解如何在记事本中使用反引号(MS)

如果我使用 powershell

使用记事本++,结果如下:

但如果我用 Windows 的记事本打开它,它就不起作用:

为什么?我该如何解决?

0 投票
3 回答
2838 浏览

bash - bash pipestatus 在反引号命令中?

在 bash 中,如果我在反引号内一起执行几个命令,如何找出第一个命令的退出状态?

即在这种情况下,我试图得到“1”。如果我不使用反引号,我可以通过 PIPESTATUS[0] 获得,但是当我想保存输出时它似乎不起作用:

更一般地说,我试图完成:将某个程序的输出的最后一行保存到一个变量中,但能够判断程序是否失败:

理想情况下,我还想了解发生了什么,而不仅仅是答案是什么。

谢谢。

0 投票
2 回答
7078 浏览

clojure - Clojure - '(撇号)和`(反引号)之间的区别

我对 Clojure 还很陌生,我不确定我是否完全理解 Clojure 中撇号和反引号之间的区别。

  1. 如果我错了,请纠正我,但在我看来,撇号阻止所有符号(即 + 和 x)解析为它们各自的 var,而反引号允许符号解析为它们的 var(但不计算值在 var 内)。这是准确的吗?
  2. 不带引号的符号 (~) 到底是做什么的?是否将 var 评估为其实际值(即函数对象的 + 符号和数字对象的 x 符号)?如果您可以根据 Clojure 的 READ-COMPILE-EVAL 阶段来解释这一点,那也会很有帮助。
0 投票
2 回答
157 浏览

perl - 使用 Perl 的段落模式分割段落之间有额外的空格

我正在尝试解析pvdisplay(8)的输出,它为每个物理卷打印一个单独的“段落”:

很简单,对吧?

事实证明,并没有我想象的那么简单。由于我的数组只得到一个项目,在键盘上敲了半个小时后,我意识到段落之间的空白行实际上在 EOL 之前包含额外的空格。根据 perlvar,$/如果设置为空字符串,则将空行视为终止符,但需要注意的是空行不能包含任何空格或制表符。当然,$/是一个字符串,而不是正则表达式,所以我不能将它设置为/^\s+$/.

我能看到的唯一方法是首先将输出保存到文件中,去除无关的空白,然后将其读回,但我不想为如此简单的东西创建一个临时文件。有没有更优雅的方法来做到这一点?

编辑:我可以使用 split(/^\s+$/m) 来做到这一点,但我只是好奇是否有办法通过更改 $/ 来做到这一点

0 投票
1 回答
89 浏览

perl - Perl 打开动态生成的文件

我正在为我的网站使用 CGI 脚本。我在打开动态生成的文件时遇到问题。这是代码:

总是失败,输出:

虽然这成功了:

我还检查了是否是反引号问题的异步执行问题,但从我对 stackoverflow 的研究来看,这似乎不是问题。我也试过这个:

我在这里发现了类似的问题,但我似乎没有与提问者相同的问题......感谢您阅读本文。

0 投票
3 回答
682 浏览

perl - Perl - Breaking out of a system/backticks command on keypress if it takes a long time

I have a problem I am hoping someone can help with...

I have a foreach loop that executes a backticks command on each iteration, such as greping a folder in a directory for a string (as shown below, greatly simplified for the purposes of explaining my question).

The problem I am having:

If the folder the backticks grep command is being run against is particularly large or the array of words to check against is particularly large then the backticks command could take hours to complete (which is fine).

But what i want to be able to do is to break out of the inner loop (i.e when a word is being greped for in a folder) and go to the next iteration if it is taking a long time when the user presses a key on the keyboard or enters the word "next" or "exit" for example.

I know that if i wasnt using backticks I could easily break out of a normal loop using something like the following (but the logic of this obviously does not work when a backticks/system call is involved):

There may be a simple solution that I am overlooking but I have never had the need to do this before, so your help is much appreciated, thanks

0 投票
1 回答
965 浏览

ruby - 如何使用反引号更改目录?

我试图通过在 Ruby 中使用反引号来更改目录。我在 Ubuntu 12.04 机器上,这是我得到的错误:

我直接通过终端运行命令,我更改目录就好了。它在我本地的 Mac 机器上也可以正常工作,所以我不确定发生了什么。

0 投票
1 回答
802 浏览

bash - Bash:使用反引号执行带有引号中的空格的命令

我编写了以下 bash 函数。它应该打印一个命令,运行它并打印它的输出,并打印一个简短的描述。

从 shell 执行时,每个日期命令都能正常工作。但是,在运行脚本时,会发生一个奇怪的错误:

运行date +%H失败,即使date +%S复杂的date +%Y-%m-%dT%H:%M:%S%z工作也很好。

有什么想法失败了print_and_run_command" date +%H" "Hour"吗?

0 投票
1 回答
1576 浏览

regex - Perl: suppress output of backtick when file not found

In my code :

It shows output : ls *error No such file or directory. How can I suppress this message. I am interested in determining that the error files are generated or not. If yes, I need the list of files else ignore (without printing the message)

0 投票
1 回答
719 浏览

bash - Bash脚本:产生多个进程问题

所以我正在编写一个脚本来调用一个进程 365 次,它们应该分 10 批运行,所以这是我写的,但有多个问题 - 1. 日志消息没有写入日志文件,我看到了错误错误文件 2 中的消息。我不断从行进程的脚本中得到这个“找不到命令”错误。3.即使命令不成功,仍然不打印FAIL而是打印成功

它有什么问题?

谢谢!