如何用另一个bash脚本创建bash脚本? [英] How create a bash script with another bash script?

查看:102
本文介绍了如何用另一个bash脚本创建bash脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个仅运行一次的bash脚本,但此后,它将创建另一个bash脚本.我尝试使用CAT EOT,但是问题是,它不是复制"/粘贴新bash中的文本,而是执行"其中的所有变量.

I'm creating a bash script that will run only once, but after that, it'll create another bash script. I've tried to use CAT EOT, but the problem is that, instead of copy/paste the text inside the new bash, it "executes" all variables inside.

例如:在新档案中写入"date=18"而不是写"date=$(date +%d)".

E.g.: instead of write "date=$(date +%d)", it is writing "date=18" in the new archive.

如何使它复制/粘贴而不是执行命令?

How can I make it copy/paste, instead of execute the command?

推荐答案

为防止变量在here-doc中扩展,请将引号引起来.

To prevent variables from being expanded in a here-doc, put quotes around the token.

cat <<'EOT'
This is a here-doc
that contains $variable
EOT

这篇关于如何用另一个bash脚本创建bash脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆