別のbashスクリプトを動的に作成しますか?

別のbashスクリプトを動的に作成しますか?

現在、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シェルスクリプトコマンドを作成し、評価を抑制し、後でスクリプトを実行する方法は?

ベストアンサー1

echo $(hostname)

すでに知っているように、コマンドが拡張されているため、これは機能しません。'コマンドの拡張を防ぐには、単一引用符を使用してください。

echo '$(hostname)'

おすすめ記事