This shell script creates a standalone Clojure executable, and it works. However, it relies on a second script file, jar_exec.
I would like the first script not to rely on the second script, but I am having difficult simulating the cp command.
How do I write
exec java -jar $0 "$@"
into the stand-alone executable without relying on a second file that contains this information?
Here is the main script that works as it now stands.
#!/bin/bash
# clj_exec
# Charles M. Norton 02/28/2012
# Creates a Clojure stand-alone executable.
#
# Change History:
#
# $Log$
#
if [ 2 -ne $# ]; then
echo "Usage: clj_exec ex-path jar-path"
exit -1
fi
cp ~/bin/jar_exec ${1}
cat ${2} >> ${1}
Here is jar_exec, which I would like to be written directly from the first script, rather than the first script relying on a second script.
#!/bin/bash
# jar_exec
# Charles M. Norton 1/7/2012
#
# Change History:
# $Log: jar_exec,v $
# Revision 1.1 2012/01/07 22:17:49 cvsuser
# jar creator for lein and other stuff.
#
#
exec java -jar $0 "$@"
You could use “here documents” like this:
This means: The stuff between
<< 'EOF'andEOFis the input to thecatcommand. This input is written to${1}. This file is made executable then. And the jar is appended to that (as in the prev. solution).Note: For brevity I’ve omitted the argument checking.
Edit:
However: Why would you do this strange stuff, when Linux and any other modern Unixoid can execute jar files right away? Just make the jar executable and run it like any other command.