设置包含文件内信息的变量

发布于 2025-01-06 11:22:21 字数 198 浏览 3 评论 0原文

我是 shell 编程新手,我需要一些有关此代码的帮助...

Buildname= test
echo $Buildname > lbuild
cbuild < lbuild
echo $cbuild

因此 echo $cbuild 必须显示创建的文本文件中的第一行。

有人可以帮我吗?

I'm new programming in shell and I need some help with this code...

Buildname= test
echo $Buildname > lbuild
cbuild < lbuild
echo $cbuild

So echo $cbuild must display the first line in the text file created.

can someone help me with that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

书间行客 2025-01-13 11:22:21

使用阅读

read -r cbuild < filename

Use read

read -r cbuild < filename
荆棘i 2025-01-13 11:22:21

我认为您要么需要在 Buildname = test 中的测试周围加双引号,要么脚本中有更多内容。 :-)

我冒昧地假设我知道你需要什么,这是我的建议:

    #! /bin/bash

    Buildname="test"
    echo $Buildname > lbuild
    cbuild=$(cat lbuild)
    echo $cbuild

I think you either want double quotes around the test in Buildname = test or there is more to the script. :-)

I took the liberty of assuming I know what you need, here's my swag at it:

    #! /bin/bash

    Buildname="test"
    echo $Buildname > lbuild
    cbuild=$(cat lbuild)
    echo $cbuild
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文