我正在编写一个名为"NewProject“的Bash,它创建了第二个名为”编译“的Bash脚本。这两个脚本都必须能够接受参数作为输入。我的问题是,我不能将"$1“写入编译脚本--这只是将NewProject的第一个参数的内容复制到编译脚本中。这是创建编译脚本的NewProject脚本的一部分。
echo "#!/bin/bash" > $1/compile
echo "
if [[ -z '$1' ]];
then
echo "You are missing file names. Type in: compile -o executable files."
exit 1
fi" >> $1/compile
chmod u+x $1/compile下面是NewProject脚本测试运行的输出。
#!/bin/bash
if [[ -z 'testproject4' ]];
then
echo You are missing file names. Type in: compile -o executable files.
exit 1
fi如何更改NewProject脚本,使编译脚本不包含'testproject4',而是包含'$1'
发布于 2014-02-05 23:34:35
我会用一本
cat <<'END' > "$1"/compile
#!/bin/bash
if [[ -z $1 ]];
then
echo "You are missing file names. Type in: compile -o executable files."
exit 1
fi
END
chmod u+x "$1"/compile当您引用本文档终止语(cat <<'END')时,它实际上引用了整个文档。
发布于 2014-02-05 23:25:00
你应该更准确地引用。
echo "$1" >>$1/compile将NewProject的第一个参数的值附加到编译脚本中。
然而:
echo '$1' >>$1/compile将精确地将$1字符附加到编译脚本中。
https://stackoverflow.com/questions/21590745
复制相似问题