“没有来自回声的输出”

huangapple go评论63阅读模式
英文:

No output from echo

问题

以下是代码部分的翻译:

#!/bin/bash
SRCDIR='/home/vinod/src'
ALLSRCFILES=${SRCDIR}/.
PODMANCMD='podman ps'
GITWORKSPACE='/workspace/vinod'
CONTAINER=$(eval "${PODMANCMD}" | awk 'NR==2{print$1}')
DSTDIR="${CONTAINER}:${GITWORKSPACE}/dst"
CPCMD=${PODMANCMD} ${ALLSRCFILES} "$DSTDIR"
echo "$DSTDIR"
echo "$CPCMD"

你提到在Linux上测试时,倒数第二个echo有输出,但最后一个没有。是否还需要其他帮助?

英文:

The below script has passed verification @ ShellCheck

#!/bin/bash
SRCDIR='/home/vinod/src'
ALLSRCFILES=${SRCDIR}/.
PODMANCMD='podman ps'
GITWORKSPACE='/workspace/vinod'
CONTAINER=$(eval "${PODMANCMD}" | awk 'NR==2{print$1}')
DSTDIR="${CONTAINER}:${GITWORKSPACE}/dst"
CPCMD=${PODMANCMD} ${ALLSRCFILES} "$DSTDIR"
echo "$DSTDIR"
echo "$CPCMD"

I get the output for the penultimate echo, but not the last one, when testing this on Linux.

Any thoughts?

TIA

答案1

得分: 2

这个语法:

CPCMD=${PODMANCMD} ${ALLSRCFILES} "$DSTDIR"

的意思是:“在一个环境中运行${ALLSRCFILES} "$DSTDIR"扩展的结果的命令,在这个环境中,环境变量CPCMD的值为${PODMANCMD}的扩展值。

这个环境只在命令的子进程中设置;它不会影响当前的 shell。

如果你想进行赋值,你需要在整个内容周围加上引号。如果在赋值的右边还有其他参数,它看起来像是一个命令的环境变量覆盖语法。

英文:

This syntax:

CPCMD=${PODMANCMD} ${ALLSRCFILES} "$DSTDIR"

Means: "Run the command resulting from the expansion of ${ALLSRCFILES} "$DSTDIR" in an environment in which the environment variable CPCMD has the value of the expansion of ${PODMANCMD}.

This environment is only set up in the child process of the command; it doesn't affect the current shell.

You want quotes around the whole thing if you want an assignment. If there are additional argument words to the right of an assignment, it looks like the environment variable override syntax for a command.

huangapple
  • 本文由 发表于 2023年7月18日 13:40:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定