我是unix的新手,并尝试使用我的shell脚本“ setup.sh”运行以下命令
if [ `grep -c 'pro-ad-assembly-0.1' /usr/local/conf/jobserver.conf` = 0 ]; then
sed -i "\$aspark {\n jobserver {\n job-bin-paths {\n ad-scala=\"/opt/scala/pro-ad-assembly-0.1-SNAPSHOT.jar\"\n }\n }\n}" /usr/local/conf/jobserver.conf
fi
但是jobserver.conf没有按预期更新并返回
include file("/hb/data/spark/job-server/jobserver.conf")
spark.context-settings.memory-per-node = ${SPARK_EXECUTOR_MEMORY}
spark {n jobserver {n job-bin-paths {n advisor-scala="/opt/scala/pro-ad-assembly-0.1-SNAPSHOT.jar"n }n }n}
因为换行符不起作用,并且在更新jobserver.conf时剩余了n
当我尝试运行
if [ `grep -c 'pro-ad-assembly-0.1' /usr/local/conf/jobserver.conf` = 0 ]; then
sed -i "\$aspark {\n jobserver {\n job-bin-paths {\n ad-scala=\"/opt/scala/pro-ad-assembly-0.1-SNAPSHOT.jar\"\n }\n }\n}" /usr/local/conf/jobserver.conf
fi
只有在终端机中才能正常工作,但是当我通过外壳脚本执行相同操作时就不能正常工作
这是我的shell脚本
#!bin/sh
# Update jobserver config
if [ `grep -c 'pro-ad-assembly-0.1' /usr/local/conf/jobserver.conf` = 0 ]; then
sed -i "\$aspark {\n jobserver {\n job-bin-paths {\n ad-scala=\"/opt/scala/pro-ad-assembly-0.1-SNAPSHOT.jar\"\n }\n }\n}" /usr/local/conf/jobserver.conf
fi
我做错了什么 谁能帮我
答案 0 :(得分:0)
#!bin / sh
sed -i'$一个火花{\ n作业服务器{\ n作业箱路径{\ n这里的文字} \ n} \ n}“'test.txt
这是一个示例脚本,在换行符“ \ n”中提供输出。