英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论