Why do we write /usr/bin/env instead of env - shebang

I know why env python is "better" than usr/bin/python and why we thus write the shebang with env.
But why don't we simply write #!env python instead of #!/usr/bin/env python ?
And why does the first option work at all? I was really surprised when I tried it.

Related

Sqlite> not showing up in Git Bash terminal

Where is the sqlite> tag on Git Bash so I know when I'm accessing sqlite? There's also no version text too.
When I enter .quit into git bash it quits out of sqlite (showing that I am accessing sqlite) but there's no tag like there is in cmd or powershell
On the cmd terminal when I access Sqlite3 it clearly shows sqlite> so I know when I'm in it.
How do I get the sqlite> tag on Git Bash?
Things like these make use of interactive terminals, and MinTTY (the underlying emulator used to run Git Bash) doesn't get along well with them. You need to prefix every such command with winpty. In this case: winpty sqlite3.

Execute a runnable .jar file from cmd without java -jar [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to execute a .jar file from command line using just the .jar file name.
For e.g.
Instead of
java -jar <jarname>.jar -a <a> -b <b>
I want to run
<jarname> -a <a> -b <b>
Is it possible. If possible how? I don't want to use batch script, since I am using apache commons cli for command line arguments parsing.
You can't do that.
What you can do, is write a shell script that does the command you don't want to do, or generate a executable wrapper. In both cases, the solution is OS-dependent. On windows, there is launch4j, on MacOS, you can create an app (that is a folder with a particular structure).
UPDATE
Actually, creating an app on MacOS is not a solution for using in a command line.
Is it possible.
No. It is not possible.
(Well ... if your shell supports a aliases or shell functions, then the user could write one. For example alias foo='java -jar foo.jar' But that's not really the same.)
For something like this, I would recommend writing a wrapper script. If you are using a platform with a POSIX compliant shell (sh, bash, etc) then it is not difficult to avoid mangling the command line arguments; e.g.
#!/bin/sh
java -jar /path/to/foo.jar "$#"
or
#!/bin/sh
java -cp /path/to/foo.jar com.acme.frobnicator.Main "$#"
For the record, "mvn" (which you cited as an example) is implemented as a shell script / batch file.
This seems to me like XY problem, that's why I'm trying to answer bit differently to what you asked...
Let say you have myjar.sh script, which will "convert"
myjar.sh -a <a> -b <b>
to
java -jar abc.jar -a <a> -b <b>
(this is doable, you can see it is Stephen Cs answer)
You just have a fear, that it will break your command line arguments parsing. The only possible way is to test and if you find it is not working we can deal with that...

Get environment variable defined in Linux bash to webpack

I have checked out tons of SO questions about "environment variables in webpack" using e.g. the DefinePlugin:
new webpack.DefinePlugin({'ENV': JSON.stringify('staging')})
but I cannot for the life of me find a way to inject an environment variable defined in the linux bash shell, instead of using the hard coded staging string
In my production and staging environements I have variables such as $ENV and $API_KEY defined, and I want to use their values in my webpack / ReactJs code.
Edit
I notice, if I run the a webpack command from cli:
$ ENVIRONMENT=staging
$ node_modules/.bin/webpack -p
And in my webpack.config.js file defines
new webpack.DefinePlugin({'ENV': JSON.stringify(process.env.ENVIRONMENT)})
This does not work (ENV is undefined in my JS code),
However, if I run it on the same line, it seems to work - ENVIRONMENT seems to be available in the webpack.config.js file:
$ ENVIRONMENT=staging node_modules/.bin/webpack -p
So I would really like to make this work without having to define the ENVIRONMENT variable on the same line as the webpack command.
In nodejs you can get your environment variables via process.env object. In your case you can do process.env.$ENV and process.env.$API_KEY to get $ENV and $API_KEY env vars respectively.
Stupid me forgot to export the variable in the bash terminal
$ export ENVIRONMENT=staging
$ node_modules/.bin/webpack -p
works fine and, as pointed out, one can then access the ENVIRONMENT variable with process.env.ENVIRONMENT from inside webpack.config.js

Running mathematica with terminal interface

I am trying to run mathematica with a terminal interface. This is so that I can submit a mathematica program as a batch job to a high performance computing cluster.
Currently I load mathematica using:
module load mathematica/9.0.1
and then type
mathematica
to run it. This however opens a GUI interface which I don't think can be submitted as a batch job. Is there anyway to achieve this baring in mind I have no sudo privileges etc
The documentation on the text-based interface to Mathematica is here:
http://reference.wolfram.com/language/tutorial/UsingATextBasedInterface.html
I know this thread is old but I want to share this for future users:
I have used Mathematica with a terminal interface. You need to write a Wolfram Language Script, which is simply a .wl file with Mathematica code in it. Once you have written your file, just execute it in your terminal like this:
Running the script file on Windows:
$ "%ProgramFiles%\Wolfram Research\Mathematica\11.1\wolfram" -script file.wl
Running the script file on Mac:
$ /Applications/Mathematica.app/Contents/MacOS/WolframKernel -script file.wl
Running the script on Linux:
$ wolfram -script file.wl

Cakephp Cake command returns No such file or directory

I have been using the cake command on my linux server for 2 years. but now im trying to move to a new server and some how the cake command gives back the error: No such file or directory
even if i give the entire path to the cake command file chmod 777 it stil wont work.
I found the solution: All I had to do is use the program dos2unix the cake file for CakePHP 2.4.2 has wrong endings when you download it with Ubuntu 13.10
I used the following command:
sudo dos2unix /path/to/cake/lib/Cake/Console/cake
I also have this problem on some servers and never figured out why this happened. I suspect the so called "shebang" might not be set correctly for every Linux distribution (e.g. if the cake script stars with #!/usr/bin/env bash, but you don't use bash on your server or your distribution doesn't have the env binary in that path, it might fail on that. This is just a theory though, as I said I never really figured it out, nor did I invest much time in investigating.
Although, what I always use as a fallback is simply calling the cake.php script (from the app folder) instead, like:
php Console/cake.php -app `pwd` bake
That never lets me down. The -app pwd bit is to tell the shell that your current directory is your app directory, so the shell can find all your files.
The REAL solution to this is to change the End-of-Line (EOL) characters to Unix format, instead of MsDos. So I guess this error will only occur if you worked in Windows.
Anyway, teh mighty
SOLUTION:
(1) Open app/Console/cake file using any text editor that allows changing of EOL characters e.g. NotePad++.
(2) In NotePad++ click:
Edit -> EOL Conversion -> Convert to Unix format
(3) Save the file and upload it to the server. Now if you navigate to the CakePHP app directory using command like:
cd /usr/share/nginx/html/cakeproject/app
...you should be able to run Console/cake without any problems and see standard output (basically help commands).
Hope this helped you!
I encountered the same problem as well, but the top answer reminded me of a similar problem I faced before: https://stackoverflow.com/a/5514351/1097483
Basically, instead of using dos2unix or installing it, you can open the file in vim, do
:set fileformat=unix
And save it.
In some versions it's possible to install cake using sudo apt-get install cakephp-scripts.
After instalation, you coud access bake anywere simple by typing bake

Resources