LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-23-2016, 09:10 PM   #1
sukhdip
Member
 
Registered: Sep 2011
Posts: 55

Rep: Reputation: Disabled
batch to shell script conversion


Hi All,

I have a small tool which is currently configured in batch scripts only. But my need is to run it on Linux platform, so I have been trying to convert a batch script to shell script.
below is the batch script:

Code:
@echo off

IF "%1"== "" GOTO ARGERR


REM UPDATE THESE PROPERTIES TO MATCH YOUR BART INSTALLATION
REM -------------------------------------------------------
SET BART_HOME=D:\BARTNEW
SET BART_VER=1.5
REM -------------------------------------------------------

REM PROVIDE SYSTEM SPECIFIC INFORMATION
REM ------------------------------------
SET JRE_HOME="C:\java\jre6"
SET BROWSER_EXE="c:\program files\internet explorer\iexplore.exe"
REM ------------------------------------


REM -------------------------------------------------
REM ******* DO NOT MODIFY THE BELOW ENTRIES *********
REM -------------------------------------------------
SET JAVA="%JRE_HOME%\bin\java.exe"
SET BART_LIB_DIR=%BART_HOME%\%BART_VER%\lib
SET XALAN_LIB=%BART_LIB_DIR%\xalan.jar
SET COMMONS_LIB=%BART_LIB_DIR%\commons-collections-3.2.1.jar;%BART_LIB_DIR%\commons-configuration-1.6.jar;%BART_LIB_DIR%\commons-lang-2.4.jar;%BART_LIB_DIR%\commons-logging-1.1.1.jar;%BART_LIB_DIR%\commons-io-1.4.jar;%BART_LIB_DIR%\xmlunit-1.2.jar
SET BART_LIB=%BART_LIB_DIR%\bart.jar
SET BART_RULES_LIB=%BART_LIB_DIR%\bart-rules.jar
SET BART_CP_EXT=%XALAN_LIB%;%COMMONS_LIB%;%BART_LIB%;%BART_RULES_LIB%;
REM -------------------------------------------------
REM CALLOUT TO CUSTOM SCRIPT IF ONE EXISTS
IF EXIST %BART_LIB_DIR%\ext\setenv.bat CALL %BART_LIB_DIR%\ext\setenv.bat
REM -------------------------------------------------

IF NOT EXIST %JAVA% GOTO JAVAERR

%JAVA% -Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl -Dbart.browser.path=%BROWSER_EXE% -classpath %BART_CP_EXT% com.sample.eai.tools.icg.bart.Bart %1
GOTO END

:ARGERR 
ECHO Usage : launch "config-filename". Eg. launch bart.cfg 
GOTO END

:JAVAERR
ECHO JRE_HOME not set correctly. Unable to locate java.exe
GOTO END

:END
set \p input="Run completed.Press Enter key to return to prompt.."
Basically this gets invoked from command line as
launch.cmd <config-file>

the above batch is saved in launch.cmd file.

Below is my effort to convert it into shell.

Code:
#!/bin/bash


# Script to convert Batch to Shell

#Set Paths for BART

export BART_HOME=/opt/BART
export BART_VER=1.5

echo "BART HOME VALUE:  $BART_HOME"
echo "BART VER VALUE: $BART_VER"

export JRE_HOME=/opt/jdk1.8.0_65/jre
echo $JRE_HOME

export JAVA="$JRE_HOME\bin\java"
export BART_LIB_DIR=$BART_HOME\$BART_VER\lib
export XALAN_LIB=$BART_LIB_DIR\xalan.jar
export COMMONS_LIB=$BART_LIB_DIR\commons-collections-3.2.1.jar;$BART_LIB_DIR\commons-configuration-1.6.jar;$BART_LIB_DIR\commons-lang-2.4.jar;$BART_LIB_DIR\commons-logging-1.1.1.jar;$BART_LIB_DIR\commons-io-1.4.jar;$BART_LIB_DIR\xmlunit-1.2.jar
export BART_LIB=$BART_LIB_DIR\bart.jar
export BART_RULES_LIB=$BART_LIB_DIR\bart-rules.jar
export BART_CP_EXT=$XALAN_LIB;$COMMONS_LIB;$BART_LIB;$BART_RULES_LIB;

$JAVA -Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl -classpath $BART_CP_EXT com.sample.eai.tools.icg.bart.Bart


echo "JAVA VALUE: $JAVA"
echo "BART LIB VALUE:  $BART_LIB_DIR"
echo "XALAN_LIB VALUE: $XALAN_LIB"
echo "COMMONS_LIB VALUE: $COMMONS_LIB"
echo "BART_LIB VALUE: $BART_LIB"
echo "BART_RULES_LIB VALUE: $BART_RULES_LIB"
echo "BART_CP_EXT VALUE:  $BART_CP_EXT"


echo "#####BART RUNN STATUS#####"

This is half done as I was in the process to convert step by step. But getting the below error for jar files configurations.

Code:
./new.sh: line 20: /opt/BART$BART_VERlibcommons-configuration-1.6.jar: No such file or directory
I got stuck here only before reaching to the even last step.
Plus I'm struggling to understand and convert the below line.

Code:
:ARGERR 
ECHO Usage : launch "config-filename". Eg. launch bart.cfg 
GOTO END
Anybody help me with this one!!!

Thanks In Advance...

Last edited by sukhdip; 02-23-2016 at 09:17 PM.
 
Old 02-23-2016, 09:57 PM   #2
kaushalpatel1982
Member
 
Registered: Aug 2007
Location: INDIA
Distribution: CentOS, RHEL, Fedora, Debian, Ubuntu, LinuxMint, Kali Linux, Raspbian
Posts: 166

Rep: Reputation: 10
Change the
Quote:
\
with
Quote:
/
and then try.
Quote:
Generally "/" use as escape character.

Last edited by kaushalpatel1982; 02-23-2016 at 09:59 PM.
 
Old 02-23-2016, 11:08 PM   #3
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,621
Blog Entries: 40

Rep: Reputation: Disabled
Quote:
Originally Posted by kaushalpatel1982 View Post
Generally "/" use as escape character.
It is the other one "\" (backslash) that serves as escape character. But it is correct that the normal slash "/" is used for file-system objects.

But back to the script that @sukhdip presented.
GOTOS are not used in shell scripts. First of all, you should try to note these commands as part of control-structures. You could use a switch-case statement but in your script simple if-else forks will do nicely. The GOTO problem will evaporate.

Where you just need to print a message, then exit, use the exit command.

The bash has a nice man page (man bash) and if you search and concentrate just on your specific points of interest, it is not too impressive. Control structures are found in the section about “Compound Commands”.

Last edited by Michael Uplawski; 02-24-2016 at 12:37 AM.
 
Old 02-24-2016, 12:31 AM   #4
sukhdip
Member
 
Registered: Sep 2011
Posts: 55

Original Poster
Rep: Reputation: Disabled
Thanks guys!!! Silly mistake by me...didn't even get a chance to see that!!

@Michael Uplawski appreciate your effort to explain it.
 
Old 02-24-2016, 03:59 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Also, its generally a good idea to make it explicit to the parser when you've got embedded vars ie vars in the middle of a string eg
Code:
export BART_LIB_DIR=$BART_HOME\$BART_VER\lib

# becomes
export BART_LIB_DIR=${BART_HOME}/${BART_VER}/lib
Due to the parsing rules, its not always reqd, but its a good habit to get into and makes it more obvious to other readers.

Some good links:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 02-24-2016, 06:25 AM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Further, a semicolom means the end of a shell command.
It needs to be \escaped or within "quotes" if part of a string.
Code:
export COMMONS_LIB="$BART_LIB_dir/commons-collections-3.2.1.jar;$BART_LIB_DIR/commons-configuration-1.6.jar;$BART_LIB_DIR/commons-lang-2.4.jar;$BART_LIB_DIR/commons-logging-1.1.1.jar;$BART_LIB_DIR/commons-io-1.4.jar;$BART_LIB_DIR/xmlunit-1.2.jar"
In general you should use quotes, and you hardly need braces.
 
  


Reply



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
Converting Batch Script to Shell Script sandeep.gcet@gmail.com Linux - Newbie 10 10-17-2013 11:36 AM
Batch file conversion to shell script aullah Linux - General 2 08-16-2011 03:00 AM
Change batch script to shell script alan.belizario Programming 5 03-31-2005 12:41 AM
Change batch script to shell script alan.belizario Linux - Software 1 03-30-2005 01:49 AM
Help w/ batch/shell script mikehlinuxquest Linux - General 5 09-13-2004 04:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:48 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration