我正在尝试从当前bash脚本动态创建bash脚本并将其写入文件。
echo "## Get the IP of the system that was assigned
#!/bin/bash
ip=$( hostname -i | xargs )
echo $ip " > second_script.sh
而不是回显正在执行它们的行,以便最终在second_script.sh中使用扩展/评估的变量。
## Get the IP of the system that was assigned
#!/bin/bash
ip=10.0.2.15
...
如何写出bash shell脚本命令并禁止评估,以后再执行该脚本?
echo $(hostname)
正如您已经意识到的那样,该命令不起作用,因为该命令已扩展。使用单引号'
防止命令扩展:
echo '$(hostname)'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句