Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 08-20-2012, 06:29 AM   #16
LQ Newbie
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled

I made some modifications, "-h" now out of case, getopt displays an error and then throws the information on how to use the script.
Eliminate long options (--book, --etc) are not relevant to the task, for now solve the problem of input parameter without "-", "--" except for b, f, l and s.
# Compile big TeX proyect 2012
# Set work dir (good idea) 
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Help funtion
echo "The big TeX Proyect 2012"
                echo "Uso:sh $0 -b -l -f -s -h"
                echo "	-b|book     : Crea libro con marcas de agua."
                echo "	-l|legal    : Crea las guías en formato legal."	
                echo "	-s|screen   : Crea las presentaciones en pdf."
                echo "	-f|facsimil : Crea los facsímiles en pdf."                
		echo "	-h|help     : Muestra la ayuda y sale."
# end help funtion
# If no argument or -h show HELP and exit
# Regexxx
if [ $# -lt 1 ]||[ "$*" = '-help' ]||[ "$*" = '-h' ]||[[ "$*" =~ $REGEX ]];then
exit 0
# Declaring getopt options
if ! options=$(getopt -o blsf -- "$@");then
    # getopt will put out an error message
echo "Uso:sh $0 -b -l -f -s -h"
exit 0
# Take proyect name from input
echo Ingrese el nombre del proyecto
read NAME
if [ -d "$DIR/store/$NAME" ]; then
    echo "Ya existe $NAME intente con otro nombre"
    exit 0
set --$options
# start script options
while [ $# -gt 0 ]; do
# Case for paramet
case $1 in
# Crea el libro desde source
		mkdir -p $DIR/backup/$NAME/book &&
		echo "Creando book $NAME"
		for file in $DIR/source/book/*.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/book/ "$file" >/dev/null 2>&1 &&
		pdflatex -output-directory=$DIR/backup/$NAME/book/ "$file" >/dev/null 2>&1
		echo "BOOK Done!";;
# Crea las guias en formato 8.5x13 pulgadas
		mkdir -p $DIR/backup/$NAME/legal &&
		echo "Creando Legal $NAME"
		for file in $DIR/source/legal/*.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/legal/ "$file" >/dev/null 2>&1
		echo "LEGAL Done!";;
# Crea las guias tipo libro plegado 6.5x8.5 in
		mkdir -p $DIR/backup/$NAME/booklet &&
		echo "Creando facsimil $NAME"
           	cp -R $DIR/source/facsimil/ /$DIR/backup/$NAME/ &&
		for file in $DIR/source/booklet/*.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/facsimil "$file" >/dev/null 2>&1
	done &&
		cd $DIR/backup/$NAME/facsimil &&
		for file in *.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/booklet/ "$file" >/dev/null 2>&1
	done &&
		cd $DIR/
		rm -rf $DIR/backup/$NAME/facsimil/
		echo "FACSIMIL Done!";;
# Crea las presentaciones usando pdfscreen
		mkdir -p $DIR/backup/$NAME/screen &&
		echo "Creando screen $NAME"
        for file in $DIR/source/screen/*.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/screen/ "$file" >/dev/null 2>&1
		echo "SCREEN Done!";;
# various
	--) shift; break;;
    -*) echo "$0: error - $1" 1>&2; exit 1;;
	 *) break;;
# Clean temp files
find $DIR/backup/$NAME/ -regextype posix-awk -regex "(.*.log|.*.toc|.*.xwm|.*.out|.*.aux)" -exec rm -rf {} \; &&
cd $DIR/backup/ &&
# Create backup folder
tar -c --xz -f $NAME-$(date +%Y%m%d).tar.xz $NAME/ 
echo "El respaldo del proyecto $NAME ha creado con exito!"
# Move proyect to store 
mv $DIR/backup/$NAME/ $DIR/store/
echo "FINISH"
exit 0
It's not perfect, but it works, I would like to fix the regular expression to only accept "-b,-l,-s,-f" and "single space -b, single space -f, etc ..." and who does not accept "-" and "--" without a character preceding it (b,l,s,f). if this is possible in bash? ...
Best for all and many thanks for links and ideas.
PD: " --book option you have called pdflatex twice using the exact same information ..." yes necessary for pdftex (table of contents and cross references).

Last edited by pablgonz; 08-21-2012 at 09:37 PM. Reason: correct spelling, change to solved


bash scripting

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help about dd command new options to put in bash script destinytia1 Linux - Newbie 10 03-08-2012 02:54 AM
bash script to rsync remote dir with options uopjohnson Linux - General 3 04-23-2010 02:16 AM
Handling null options in a bash script which ought to have a value dairo Linux - General 2 03-16-2009 01:27 PM
bash script: making options? johngreenwood Programming 4 01-04-2007 02:55 PM
add reload and restart options to the firewall script cccc Debian 2 09-27-2006 05:11 AM

All times are GMT -5. The time now is 11:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration