I have a snippet of code to compile a tex document.
#!/usr/bin/env bash
filename="thesis"
pdflatex -shell-escape $filename
makeglossaries $filename
bibtex $filename
pdflatex $filename
pdflatex $filename
# for Ubuntu
#xdg-open $filename.pdf
# for mac
open $filename.pdf
How do I make this script work on both Linux and OS X? I think it should be something like,
if is Linux; then
xdg-open $filename.pdf
elif is OS X; then
open $filename.pdf
fi
The standard way to detect the current platform is to call uname
:
uname=$(uname);
case "$uname" in
(*Linux*) openCmd='xdg-open'; ;;
(*Darwin*) openCmd='open'; ;;
(*CYGWIN*) openCmd='cygstart'; ;;
(*) echo 'error: unsupported platform.'; exit 2; ;;
esac;
"$openCmd" "$filename.pdf";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With