bash – Convert .bat file to .sh file – Education Career Blog

I have to convert the following .bat code in the .sh code

echo Setting Bonita Environment variable
set "JAVA_OPTS=%JAVA_OPTS% -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory"
set "JAVA_OPTS=%JAVA_OPTS% -Djava.naming.provider.url=jnp://localhost:1099"    
set "LOG_OPTS= -Djava.util.logging.config.file=D:\jboss-5.0.0.CR2-jdk6\jboss-5.0.0.CR2\server\default\conf\"
set "SECURITY_OPTS=\jboss-5.0.0.CR2-jdk6\jboss-5.0.0.CR2\server\default\conf\jaas-standard.cfg"
echo %JAVA_OPTS%

Please guide me to do that. Thanks.


echo Setting Bonita Environment variable
JAVA_OPTS="$JAVA_OPTS -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory"
JAVA_OPTS="$JAVA_OPTS -Djava.naming.provider.url=jnp://localhost:1099"
echo "$JAVA_OPTS"


It’s a fairly simple conversion job:

  • All variables of the form %xyz% should be replaced with ${xyz}.
  • All set statements should be export.
  • Your set "abc=xyz" type statements should be export abc="xyz" (different position for quotes).
  • Paths, of course, should reflect the Linux filesystem (no drives, forward slashes, different locations).
  • If you want to use those variables once the script is finished, you need to source it or . it, not run it. Running it will create those variable in a sub-shell, not your desired shell.

Leave a Comment