【发布时间】:2022-12-18 15:35:18
【问题描述】:
我需要创建一个文件供后续nohup执行,该文件包含一些变量,我不希望通过文件生成时变量是replaced。
当我在生成的脚本中使用以下代码执行代码时,all the variables were replaced,这不是我所期望的。
#!/bin/bash
gen_script() {
filepath=$1
if [ ! -f "$filepath" ]; then
cat >${filepath} <<EOF
#!/bin/bash
# Code generated by main.sh; DO NOT EDIT.
test(){
ip=$1
port=$2
restorefile=$3
redis-cli -h $ip -p $port --pipe < $restorefile
}
test "$@"
EOF
fi
}
main(){
gen_script exec.sh
nohup bash exec.sh $1 $2 > nohup.out 2>&1 &
}
main "$@"
请问如何更改我的代码?我真的很感激任何帮助。
【问题讨论】: