问题标签 [command-substitution]
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.
bash - Grouping command substitution without double quotes? "$()" without the ""
I'm writing a script that involves generating Awk programs and running them via awk $(...)
, as in
The generated program is going to be more complicated in the end, but first I want to make sure this is possible. In the past I've done
where the grouping is unsurprising. But the first example (under GNU awk, which gives a more helpful error message than mawk which is default on my other machine) gives
presumably because this is executed as awk BEGIN { print "hello!" }
rather than awk 'BEGIN { print "hello!" }'
. Is there a way I can force $(...)
to remain as one group? I'd rather not use "$()"
since I'd have to escape all the double-quotes in the program generator.
I'm running Bash 4.2.37 and mawk 1.3.3 on Crunchbang Waldorf.
bash - 命令替换和撤消的后台任务
有没有办法强制命令替换退出,让 baground 任务撤消?
例子:
在没有命令替换的情况下运行它:
使用命令替换:
bash - 如何解决 Bash 命令替换中的错误“bash: !d': event not found”
我正在尝试解析 VNC 服务器启动事件的输出,但在命令替换中使用 sed 进行解析时遇到了问题。具体来说,远程VNC服务器的启动方式如下:
然后解析在此启动事件中产生的标准错误输出,以便提取服务器并显示信息。此时变量的内容VNCServerResponse
如下所示:
可以通过以下方式解析此输出,以便提取服务器并显示信息:
结果如下所示:
我想要做的是在命令替换中使用这个解析,如下所示:
在尝试执行此操作时,我收到以下错误:
我不知道如何解决这个问题。在命令替换中使用 sed 的方式似乎是一个问题。我会很感激指导。
bash - 在命令替换内的 awk 中传递变量
我是新手,正在学习如何获取变量。如何在命令替换中获取打印可变部分?谢谢。
linux - 在shell脚本中将文件路径作为字符串读取
我的目标 --> 命令中的文件列表必须逐行读取并用作另一个命令的一部分。
说明 --> linux中的一个命令返回
它存储在changed_files
变量中。我使用以下 while 循环逐行读取文件并将其用作 pmd 命令的一部分
我是编写 shell 脚本的新手,但我的假设是这些行会在循环中分开并在每次迭代中打印,但我得到以下错误 -
你能告诉我如何将值作为字符串而不是作为打开的文件获取。顺便说一句,该文件确实存在,这让我感到更加困惑。(后来在命令中使用它)。我会对任何有助于我理解和解决此问题的答案感到满意。
linux - 将命令替换为远程 sed 命令
我想编写一个 Unix 命令,从 /etc/passwd 中选择一个随机用户,并使用 SHH 检查远程主机以确定是否存在具有相同 UID 的用户,如果用户存在,则从 passwd 打印出整行。
这是我到目前为止写的命令:
似乎 sed 命令不将 xargs 作为本地机器的参数,而是将文本
任何想法将不胜感激!
bash - 如何在不调用命令替换的情况下调用 Bash 函数?
我有一个具有 Perl 风格的“或死”的 Bash 函数。例如,
直接调用函数让我利用exit
. 但是,如果该函数返回一个我想使用的值,则命令替换不适用于exit
. 即exit只存入返回值$?
,执行下一行。
使用调试选项运行-x
似乎意味着命令替换类似于子shell,因为 bash 为它输出更深的嵌套。因此,exit
不适用于主脚本。
样本输出:
有没有办法调用 func1 并使用它的输出(在变量、循环、if 等中),同时仍然利用短路exit
?
bash - Do escaped double quotes in command substitution become literals in Bash?
If I execute this in Bash
I get 1 2
. But if I execute
I get "1 2"
.
Now I would figure if I execute
I would get 1 2
. But again, I get "1 2"
. In fact, no matter how many command substitutions in the chain
I always get "1 2"
. Why is that?
ant - Apache Ant exec 任务中的扩展参数
我有一个构建需要一个任务来启动一个进程,并且需要一个在最后杀死它。
我有一个包含进程 ID 的文件,但无法弄清楚如何让 ant 扩展命令替换以便将该文件的内容传递给 kill 命令。
我努力了:
和:
但两者都转换为字符串文字,因此导致:
[exec] kill: failed to parse argument: '$(cat process-file)'
有没有办法让蚂蚁扩展这些?或者完全不同的途径来实现这一点?