Linux 打印消息时出错 方法
我有一个ang脚本,它通过扩展名执行文件聚合,创建一个提交并使用推送进行上传。 这是:Linux 打印消息时出错 方法,linux,bash,git,github,Linux,Bash,Git,Github,我有一个ang脚本,它通过扩展名执行文件聚合,创建一个提交并使用推送进行上传。 这是: function LsAddCm () { echo -e 'Enter the extension' read rExtension # AEFO-Started : #Audio-WB Creación de 'AEFO_00SL_AudioWB/' # CM1 => AEFO-Started : echo -e 'Enter the first part [ AEFO-Started : ]'
function LsAddCm () {
echo -e 'Enter the extension'
read rExtension
# AEFO-Started : #Audio-WB Creación de 'AEFO_00SL_AudioWB/'
# CM1 => AEFO-Started :
echo -e 'Enter the first part [ AEFO-Started : ]'
read CM1
# CM2 => #Audio-WB
echo -e 'Enter the second part [ #Audio-WB ]'
read CM2
# CM3 => Creación de {...}
echo -e 'Enter the third part [ Creación de ]'
read CM3
#message="AEFO-Started : #Audio-WB Creación de "
echo "'${CM1}' '${CM2}' '${CM3}'"
time ls | awk -F . '{print $1}' | xargs -n1 sh -c 'git add $1.'${rExtension}' && git commit -m "'${CM1}' '${CM2}' '${CM3}' $1.'${rExtension}'" && git push' sh
}
# Execute the program, in anothers words, runnning the function necesary
function run (){
echo run ✅
LsAddCm
}
run
问题
问题是,当我想将一个变量作为消息,并在执行时引入一个空格时,输出为:
$ sh s1.sh
run ✅
Enter the extension
mp3
Enter the first part [ AEFO-Started : ]
A 1
Enter the second part [ #Audio-WB ]
A 2
Enter the third part [ Creación de ]
A 3
'A 1' 'A 2' 'A 3'
1 A: -c: line 0: unexpected EOF while looking for matching `"'
1 A: -c: line 1: syntax error: unexpected end of file
1 A: -c: line 0: unexpected EOF while looking for matching `"'
1 A: -c: line 1: syntax error: unexpected end of file
1 A: -c: line 0: unexpected EOF while looking for matching `"'
1 A: -c: line 1: syntax error: unexpected end of file
real 0m0,899s
user 0m0,061s
sys 0m0,447s
问题:
如何修复它?解决方案(更正)
引用所有变量确实可以解决错误,换句话说,要正确打印,必须更正以下行:
time ls | awk -F . '{print $1}' | xargs -n1 sh -c 'git add $1.'${rExtension}' && git commit -m "'${CM1}' '${CM2}' '${CM3}' $1.'${rExtension}'" && git push' sh
通过以下方式:
time ls | awk -F . '{print $1}' | xargs -n1 sh -c 'git add $1.'"${rExtension}"' && git commit -m "'"${CM1}"' '"${CM2}"' '"${CM3}"' $1.'"${rExtension}"'" && git push' sh
引用你的变量<代码>${CM1}→ <代码>“${CM1}”等是你的朋友。我试着把它作为`和'旁边',但什么都没有……我不确定你在说什么,但我相当肯定引用变量会解决问题……我可以用
foo='bar baz';sh-c'echo'${foo}'
产生类似的错误,用foo='bar baz';sh-c'echo'${foo}'解决它“
@NicolásAlarcónR.我已经尝试了你的代码(逐字逐句),我得到了相同的错误,引用所有变量确实解决了错误:time ls | awk-F。”{print$1}'|xargs-n1 sh-c'git add$1.“${rExtension}”和&git commit-m“${CM1}”“${CM2}”“${CM3}”'$1.“${rExtension}”和&git push'sh