有没有办法使用Bashscript动态生成Bashscript,更改生成的Bashscript的mod以允许执行,然后运行生成的Bashscript?
答案 0 :(得分:7)
是的,这完全可行!
#!/bin/bash
FILE="/tmp/generated.bash"
cat <<END > $FILE
#!/bin/bash
echo "Hello There from generated script!"
END
chmod 755 $FILE
echo "running ...."
$FILE
echo "done"
会给你输出如下:
[tmp]=> ./test.bash
running ....
Hello There from generated script!
done