Kelan Poten-Coyle
Kelan Poten-Coyle

Reputation: 305

How would I remake a Batch File into a Shell Script

I'm using Sublime Text 2, and I want to be able to compile and run Java Files with one button.

When running Windows, the Batch file Required is:

@ECHO OFF
cd %~dp1
javac %~nx1
java %~n1

I'm wondering what that would look like in a Shell Script, cause I don't know much about Shell Scripts...

I'm using the Open JDK and JRE in case it matters.

Thanks for the help,

Kelan

Upvotes: 0

Views: 291

Answers (2)

Jonathan Callen
Jonathan Callen

Reputation: 11561

The bash equivalent to that script would be something like:

#!/bin/bash
cd "$(dirname "$1")"
javac "$(basename "$1")"
java "$(basename "$1" ".${1##*.}")"

Upvotes: 3

djangofan
djangofan

Reputation: 29669

A shell script would STILL require running a batch file to start it. For example, you could write a Ant task that could do what you are asking, or perhaps a Beanshell script. But, you still wont be able to avoid making a batch file that launches it. The batch file that you are using now is as close as you'll get to a single click solution. Not even a PowerShell script would give you better convenience.

Upvotes: 0

Related Questions