我正在尝试编写一个小脚本,它将简化检查latex文件之间的版本更改。在脚本中,我使用git show
来提取文件的指定版本,但我遇到了问题。
到目前为止,这是我的脚本:
#!/bin/bash
# A cl interface to compare changes between git versions of a latex doc
# Select tex file to examine
tex1=$(ls *.tex| slmenu -p "Select a tex file: ")
## Select branch
branches=$(git branch | cut -c3-)"\nHEAD"
branch=$(echo $branches | slmenu -p "Select the branch to compare to:")
# Select how many steps ago
echo "How far back? (see git reflog)"
read steps
treeish=$(echo $branch'~'$steps":'"$tex1"'")
echo "Will compare to this branch position:"
echo $treeish
git show $treeish > temp.tex
我正在测试的文件有空格字符。在这里运行代码时,完整输出以及错误:
Select a tex file: SMART Reporting Tutorials.tex SMART Reporting Tutorials.tex
Select the branch to compare to: HEAD HEAD
How far back? (see git reflog)
1
Will compare to this branch position:
HEAD~1:'SMART Reporting Tutorials.tex'
fatal: Path ''SMART' does not exist in 'HEAD~1'
尝试运行git show $treeish > temp.tex
但是,如果我复制回声的结果,
HEAD~1:'SMART Reporting Tutorials.tex'
,并使用git show:
git show HEAD:'SMART Reporting Tutorials.tex'
我觉得它运作得很好。所以我想我的问题是......为什么我的BASH脚本失败了,但是当我把它输入终端时工作正常?
答案 0 :(得分:1)
您可能需要引用$ treeish以防止解释空格字符。你的最后一行将成为:
git show "$treeish" > temp.tex