linux - 错误打印消息
问题描述
方法
我有 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 : ]'
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
推荐阅读
- python - 将新数据表写入 excel 文件时删除了原始工作表
- reactjs - 使用带有回调的对象反应 setState()
- r - 将 R 中的 data.frame 列表转换为双精度列表
- nlp - 对于 Gensim 4.0,如何使用预训练的模型并用我自己的语料进一步训练它?
- google-app-engine - 迁移谷歌云 App Engine 标准区域
- python - python re.compile(“regex”).search 返回 span(0, 0) match=“”
- java - 如何更改语音结果关闭之前的时间CMUSphinx4
- json - 通过 ELK 堆栈加载多个递增的 json 文件
- postgresql - 如何在 postgresql 中删除每个用户的一条重复记录
- python - pyspark sql中带有正则表达式的case语句