LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
LinkBack Search this Thread
Old 08-16-2012, 12:37 AM   #1
pablgonz
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Rep: Reputation: Disabled
add options to bash script


Hello forum friends, I have the following bash script (which works perfectly), the code is as follows:
Code:
#!/bin/bash
# Compile big TeX proyect
# Set work dir
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Take name for proyect and create dir (mandato...)
echo Enter Name of proyect
read NAME
mkdir -p $DIR/backup/$NAME/{book,screen,legal,booklet}
echo "El Arbol de directorios para $NAME ha sido creado"
# First Option
# Compiling book (2 run) 
for file in $DIR/source/book/*.tex 
do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/book/ "$file" >/dev/null 2>&1 &&
   pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/book/ "$file" >/dev/null 2>&1
done
echo "El Libro se ha creado con exito!"
# Second Option
# Compiling screen
for file in $DIR/source/screen/*.tex 
do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/screen/ "$file" >/dev/null 2>&1
done
echo "Las Presentaciones se han creado con exito!"
# Third Option
# Compilando legal
for file in $DIR/source/legal/*.tex 
do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/legal/ "$file" >/dev/null 2>&1
done
echo "El formato LEGAL se ha creado con exito!"
# Fourth Option
cp -R $DIR/source/facsimil/ /$DIR/backup/$NAME/ 
for file in $DIR/source/booklet/*.tex 
do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/facsimil "$file" >/dev/null 2>&1
done 
cd $DIR/backup/$NAME/facsimil &&
for file in *.tex 
do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/booklet/ "$file" >/dev/null 2>&1
done
# Clean temp files and facsimil dir
rm -rf $DIR/backup/$NAME/facsimil/ &&
find $DIR/backup/$NAME/ -regextype posix-awk -regex "(.*.log|.*.toc|.*.xwm|.*.out|.*.aux)" -exec rm -rf {} \; &&
cd $DIR/backup/ &&
# Create back folder
tar -c --xz -f $NAME-$(date +%Y%m%d).tar.xz $NAME/ 
echo "El respaldo $NAME.tar.xz se ha creado con exito!"
# Move proyect
mv $DIR/backup/$NAME/ $DIR/store/
echo "The $NAME proyect its done"
exit 0
but, I would like to run it in parts, that is, add options to run.
My idea is to add the following
- book (create book)
- booklet (create booklet)
- screen (create screen)
- legal (make legal)
- all (all formats)
try to get married, but did not get what he wanted (I should clarify that I am not a programmer, and I believe it from google, this and other forums Linux users) if you help me with some example, or tell me I should improve on this script, would appreciate it.
regards
This its a second version (using case)
Code:
#!/bin/bash
# Compile big TeX proyect
# Set work dir
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo Ingrese el nombre del proyecto
read NAME
echo 'Ingresa los parámetros'
read par
case $par in
        -b|book)
		mkdir -p $DIR/backup/$NAME/book &&
                echo "Creando libro para $NAME"
                for file in $DIR/source/book/*.tex 
		do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/book/ "$file" >/dev/null 2>&1 &&
		   pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/book/ "$file" >/dev/null 2>&1
		done
		echo "Done!"
                ;;
        -l|legal)
		mkdir -p $DIR/backup/$NAME/legal &&
		for file in $DIR/source/legal/*.tex 
		do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/legal/ "$file" >/dev/null 2>&1
		done
		echo "Done!"
	        ;;
        -f|facsimil)
		mkdir -p $DIR/backup/$NAME/booklet
                cp -R $DIR/source/facsimil/ /$DIR/backup/$NAME/ &&
		for file in $DIR/source/booklet/*.tex 
		do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/facsimil "$file" >/dev/null 2>&1
		done &&
		cd $DIR/backup/$NAME/facsimil &&
		for file in *.tex 
		do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/booklet/ "$file" >/dev/null 2>&1
		done &&
		rm -rf $DIR/backup/$NAME/facsimil/
                ;;
	-s|screen)
		mkdir -p $DIR/backup/$NAME/screen &&
                for file in $DIR/source/screen/*.tex 
		do pdflatex -interaction=batchmode -output-directory=$DIR/backup/$NAME/screen/ "$file" >/dev/null 2>&1
		done
		echo "Done!"
                ;;

        *)
                echo "The big TeX Proyect"
                echo "Usage: $0 {book|legal|facsimil|screen}"
                echo "	book     : Crea libro con marcas de agua."
                echo "	legal    : Crea las guías en formato legal."	
                echo "	screen   : Crea las presentaciones en pdf."
                echo "	facsimil : Crea los facsímiles en pdf."	
	;;
esac
# 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
mv $DIR/backup/$NAME/ $DIR/store/
echo "FINISH"
exit 0
but stay trapped to give more than one option to the script (-b -f -s -l and create the option - all)
Pablo

Last edited by pablgonz; 08-16-2012 at 01:15 AM.
 
Old 08-16-2012, 08:29 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Please don't double-post your requests. Keep everything to one thread. I just finished replying to your other one here:

http://www.linuxquestions.org/questi...pt-4175422321/

I'm reporting this to the mods so they can decide what to do, considering that this thread has additional info. They may have to merge them in some way.
 
Old 08-16-2012, 09:05 AM   #3
pablgonz
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
apologies, I did not realize that it has doubled the post (I thought I had edited), do not know how to delete ...
 
Old 08-16-2012, 09:52 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Any time you have trouble with your post (double posting, wrong forum), just hit the "report" button at the bottom of it, and ask the moderators to fix it.
 
Old 08-17-2012, 03:28 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,527

Rep: Reputation: 147Reputation: 147
Please post all replies to http://www.linuxquestions.org/questi...pt-4175422321/

This thread is closed.
 
Old 08-17-2012, 03:29 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,527

Rep: Reputation: 147Reputation: 147
Please post all replies to http://www.linuxquestions.org/questi...pt-4175422321/

This thread is closed
 
  


Reply

Tags
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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] add options to bash script pablgonz Programming 15 08-20-2012 05:29 AM
Need Help about dd command new options to put in bash script destinytia1 Linux - Newbie 10 03-08-2012 01:54 AM
Handling null options in a bash script which ought to have a value dairo Linux - General 2 03-16-2009 12:27 PM
bash script: making options? johngreenwood Programming 4 01-04-2007 01:55 PM
add reload and restart options to the firewall script cccc Debian 2 09-27-2006 04:11 AM


All times are GMT -5. The time now is 07:27 AM.

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