I'm trying to write a small script which will streamline checking version changes between latex files. In the script, I'm using git show
to pull the specified version of the file, but I'm running into issues.
Here's my script so far:
#!/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
The file I'm testing on has white space characters. When running the code here's the full output along with the error:
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'
The error happens at line 21 when trying to run git show $treeish > temp.tex
However, if I copy the results of the echo,
HEAD~1:'SMART Reporting Tutorials.tex'
, and manually write it into the terminal with git show:
git show HEAD:'SMART Reporting Tutorials.tex'
I see it works just fine. So I guess my question is... Why does this fail in my BASH script, but works fine when I enter it into the terminal?