shebang

Make Node.js support the shebang (#!) for JavaScript files

放肆的年华 提交于 2019-11-27 17:20:44
问题 Some scripting languages (such as Python or Bash) use # for comments. #!/usr/bin/env python print 'hello, world' I can run the script: python script.py Or ./script.py Is it possible to make JavaScript support shebang? 回答1: Yes, you can simply use #!/usr/bin/env node (or whatever the name of your JavaScript interpreter is, it works fine with js (spidermonkey), too). [me@hades:~]> cat > test.js #!/usr/bin/env node console.log('hi'); [me@hades:~]> chmod +x test.js [me@hades:~]> ./test.js hi Most

How does argparse (and the deprecated optparse) respond to 'tab' keypress after python program name, in bash?

谁都会走 提交于 2019-11-27 13:13:03
问题 I have tested optcomplete working with the optparse module. Its example is a simple file so I could get that working. I also tested it using the argparse module as the prior one is deprecated. But I really do not understand how and by whom the python program gets called on tab presses. I suspect bash together with the shebang line and the argparse (or optparse ) module are involved in some way. I have been trying to figure this out (now gonna read the source code). I have a little more

run python script directly from command line

孤街醉人 提交于 2019-11-27 12:31:13
#!/usr/bin/env python I put that at the top of a script. I've seen that should make the script runnable from the command line without the need for python programname.py . Unless I'm misunderstanding I should be able to use programname.py as long as I have the above line at the top of the script. Is this correct? It isn't working for me I just get an error indicating that I would have to use python at the beginning of the 'call'. Universal running of Python scripts You can pretty much universally run without the shebang ( #! ) with python myscript.py Or nearly equivalently (it places the

What should I use for a Perl script's shebang line?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 12:18:03
Which of these is better or faster to use as the shebang line for a Perl script? #! perl #! perl.exe #! fullpath/perl(/perl.exe) #! partialpath/perl(/perl.exe) And, when using #!perl , when it works on a particular system, how do I find out in the script which perl interpreter I'm using so I can put that one into the shebang line? And, if using a /path/path/perl , are * or ... allowed to be used for the folders? If you have to hard code #!, use #!/usr/bin/env perl . Why? What you want is for the Perl program to run with the user's preferred Perl. That's going to be the first on in their PATH .

Why does this snippet with a shebang #!/bin/sh and exec python inside 4 single quotes work?

和自甴很熟 提交于 2019-11-27 11:50:53
I'm trying to understand one of the answers to this question: Cannot pass an argument to python with "#!/usr/bin/env python" #!/bin/sh ''''exec python -u -- "$0" ${1+"$@"} # ''' This works well, but I do not understand why it works with four ticks at the beginning of that line rather than three. In addition, why the hash near the end of that string? Python supports triple-quoted strings: '''something''' Shell supports only single-quoted strings: 'something' By using four quotes, sh sees that as 2 empty strings, but Python sees the first three as the start of a triple-quoted string, and

node and shebang : help executing via command line

自作多情 提交于 2019-11-27 11:03:05
问题 My node installation is at: /usr/local/bin/node and I've added the shebang: #!/usr/local/bin/node to the top of the file and given my node app file the permissions 755, but when I try to run: > ./my-app I get the old: -bash: ./my-app: No such file or directory What am I doing wrong? 回答1: The node shebang is: #!/usr/bin/env node Not all systems place node in the same location, its possible that you have the location incorrectly. This will find them all. Source Also 来源: https://stackoverflow

Proper shebang for Python script

痞子三分冷 提交于 2019-11-27 09:46:10
问题 I'm usually using the following shebang declaration in my Python scripts: #!/usr/bin/python Recently, I've came across this shebang declaration: #!/usr/bin/env python In the script documentation, it was noted that using this form is "more portable". What does this declaration mean? How come there's a space in the middle of the path? Does it actually contribute to protability? 回答1: #!/usr/bin/env python is more portable because in general the program /usr/bin/env can be used to "activate" the

Shebang line limit in bash and linux kernel

独自空忆成欢 提交于 2019-11-27 04:58:53
I'm trying to execute python scripts automatically generated by zc.buildout so I don't have control over them. My problem is that the shebang line (#!) is too long for either bash (80 character limit) or direct execution (some Linux kernel constant I don't know). This is an example script to help you reproduce my problem: #!/././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././././bin/bash echo Hola! How can be bash or the kernel configured to allow for bigger shebang

Appropriate hashbang for Node.js scripts

不羁的心 提交于 2019-11-27 03:01:01
问题 I'm trying to create a script for node.js that will work in multiple environments. Particularly for me, I'm switching back and forth between OS X and Ubuntu. In the former, Node is installed as node , but in the latter it is nodejs . At the top of my script, I can have: #!/usr/bin/env node or #!/usr/bin/env nodejs I'd rather have the script run as an executable for either environment as long as node is installed rather than have one or the other have to specify the command ( ./script-name.js

What exactly does “/usr/bin/env node” do at the beginning of node files?

那年仲夏 提交于 2019-11-27 02:31:38
I had seen this line #!/usr/bin/env node at the beginning of some examples in nodejs and I had googled without finding any topic that could answer the reason for that line. The nature of the words makes search it not that easy. I'd read some javascript and nodejs books recently and I didn't remember seeing it in any of them. If you want an example, you could see the RabbitMQ official tutorial , they have it in almost all of their examples, here is one of them: #!/usr/bin/env node var amqp = require('amqplib/callback_api'); amqp.connect('amqp://localhost', function(err, conn) { conn