gpt4 book ai didi

linux - 如何在一行中执行多个命令?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:08:33 26 4
gpt4 key购买 nike

我是 Linux 新手,遇到无法完全执行这些代码行的问题。我已经研究了几个小时,也花了很多时间自己操纵这些,但仍然无法创造出看起来应该如何的东西。提前谢谢大家。

它应该是什么样子:

$. network.sh
Today is: Day, Month, Day (numerical), year
The hostname for localhost.localdomain is: 192.168.xxx.xxx

这是它目前的样子。

 . network.sh
Today is: Sunday, October 11, 2015
The hostname for localhost.localdomain
is: [kris@localhost Desktop]$

is 在下一行。这完全无视我的最后一行命令,并且不会将其显示在与“localhost.localdomain 的主机名”相同的行上。

当前文件...

#!/bin/bash
# Script to print the current date
echo -n "Today is: "
d=$(date +%A," "%B" "%d," "%Y)
echo "$d"
# Show IP in color
echo -n "The hostname for " ; hostname ; echo -n "is:" ; echo -n ip addr list eth1 |grep "inet " |cut -d' ' -f6|cut -d/ -f1

最佳答案

只需插入子流程输出:

echo "The hostname for $(hostname) is: $(ip addr list eth1 |grep "inet " |cut -d' ' -f6|cut -d/ -f1)"

嵌套的 " 没问题($(subshel​​l) 解析优先)

关于linux - 如何在一行中执行多个命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33069519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com