Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何在脚本shell sh中转义默认写入值的空间?_Git_Shell_Plist - Fatal编程技术网

Git 如何在脚本shell sh中转义默认写入值的空间?

Git 如何在脚本shell sh中转义默认写入值的空间?,git,shell,plist,Git,Shell,Plist,我想在plist中编写一些东西,为此我使用脚本shell。 我同时在训练shell脚本。 我只是尝试获取git log命令的三个第一输出行,并将输出放在info.plist的属性中 我的剧本: output=$(git log | head -n 3) file=$(echo $PWD)/info # write it to the Info.plist defaults write "$file" gitLog $output 此命令的输出:$(git log | head-n3) 我希

我想在plist中编写一些东西,为此我使用脚本shell。 我同时在训练shell脚本。 我只是尝试获取git log命令的三个第一输出行,并将输出放在info.plist的属性中

我的剧本:

output=$(git log | head -n 3)
file=$(echo $PWD)/info 

# write it to the Info.plist
defaults write "$file" gitLog $output
此命令的输出:$(git log | head-n3)

我希望我能很好地解释我的问题

帮助请尝试使用:

output=$(git log | head -n 3)
file=$(echo $PWD)/info 

defaults write "$file" gitLog -string "$output"
如果要将3行文本存储为“一个字符串”

或者下一个:

OIFS=$IFS
IFS=$'\n'
declare -a output=( $(git log | head -n 3) )
IFS=$OIFS

file=$(echo $PWD)/info 
defaults write "$file" gitLog -array "${output[0]}" "'${output[1]}'" "${output[2]}"

如果您想将3行存储为“数组”。

您引用的是
$file
,为什么不
$output
?当我引用
output
时,它告诉我他无法解析输出结果,然后它说:尝试单次引用它。我尝试了单引号,它没有任何作用,我的属性是空的:第一个解决方案非常有效!非常感谢。我刚刚不得不添加字符串参数!完美的
output=$(git log | head -n 3)
file=$(echo $PWD)/info 

defaults write "$file" gitLog -string "$output"
OIFS=$IFS
IFS=$'\n'
declare -a output=( $(git log | head -n 3) )
IFS=$OIFS

file=$(echo $PWD)/info 
defaults write "$file" gitLog -array "${output[0]}" "'${output[1]}'" "${output[2]}"