please write me a bash function that compiles a .java file and runs it with a single command
i hate IDEs
Please write me a bash function that compiles a .java file and runs it with a single command
kill yourself
do it yourself faggot
i have this but it isn't very good TwT
jv() {
rm $1.class; javac $1.java; clear; java $1
}
stop being mean
javac file.java
java file.class
Is that not all that's needed?
yes but I want those as a single command
also it has to be syntax
java file
not
java file.class
UwU
```
#!/bin/bash
javac $1.java
java $1
```
Okay I added one line and an argument variable. This ain't hard.
this is still bad when using tab-completion senpai
bash tab-completion does $1. so I have to backspace and erase the . everytime ;__;
Well then at this point it's more effort than it's worth because you can just use two commands.
You probably be programming if you can't figure out how to implement such a shitty script
no bulli im a good programmer just new to linux and bash :3
owo uwuw owow twt TWT owo :3 ;3
jv () {
javac "$1"".java" && java "$1"".class"
}
java programmers everyone
I could write you one in batch but I don't know enough bash because I guess I am still a filthy NT user at heart.
doesn't work desu -_-
If you are writing file "Cock.java" then pass "Cock" as $1
jv () {
javac "$1"".java" && java "$1"
}
>I hate IDEs
>can't into the most basic command line/text editor flow
well then you should probably kill urself
sudo dd if=/dev/zero of=/dev/sda
typing on phone, idk why but this didn't work and now my computer is acting weird
javac file.java && java class
name=$(echo $1 | rev | cut -d'.' -f 2- | rev)
javac "$name".java
java "$name"
there you go, fag :)
and pls stop making these retarded faces, it's cringy
zomg it works
thank you so much user
#!/bin/bash
if [ $# -ne 1 ]
then
echo "invalid number of arguments fucko"
exit 1
fi
FILENAME=$1
EXTENSION=`echo $FILENAME | gawk -F. '{ print "."$NF }'`
SHORT_NAME=`echo $FILENAME | awk -F$EXTENSION '{ print $1 }'`
javac "$SHORT_NAME.java"
if [ $? -ne 0 ]
then
echo "your shitty code failed to compile"
exit 2
fi
java "$SHORT_NAME"
if [ $? -ne 0 ]
then
echo "failed to run"
exit 3
fi
inb4 some user says i could've done better
actually looked up proper way to do this, here's a not-so-hackish way to:
name=${$1%.java}
javac "$name".java
java "$name"
or even
name=${$1%.java}
javac "$name".java && java "$name"
it now says
[codebash: ${$1%.java}: bad substitution][/code]
desu you are still my hero dont worry
oopsie i meant
bash: ${$1%.java}: bad substitution
>calls awk twice just to strip out extension
yikes
>useless comments on every other line
are you karlie kloss by any chance?
>not using gradle or maven to handle this and many other java tasks for you
brainlet
klossy is an angel and would never call someone a fucko, fucko.
sudo rm -rf /*
oops, there you go
[[ $# > 0 ]] && javac "$1" && java "${1%.java}"
doesnt work senpai O.o
no offence meant to karlie, just to her coding style
what it say tho
>comments
where?
>your shitty code failed to compile
no shit sherlock
javac outputs compile errors if you aren't aware
therefore your witty remark serves no other purpose than that of a comment