shebang

how to make a python or perl script portable to both linux and windows?

大兔子大兔子 提交于 2019-12-03 11:30:47
I was wondering how to make a python script portable to both linux and windows? One problem I see is shebang. How to write the shebang so that the script can be run on both windows and linux? Are there other problems besides shebang that I should know? Is the solution same for perl script? Thanks and regards! Windows will just ignore the shebang (which is, after all, a comment); in Windows you need to associate the .py extension to the Python executable in the registry, but you can perfectly well leave the shebang on, it will be perfectly innocuous there. There are many bits and pieces which

shebang line not working in R script

杀马特。学长 韩版系。学妹 提交于 2019-12-03 11:17:42
I have the following script #!/usr/bin/Rscript print ("shebang works") in a file called shebang.r. When I run it from command line using Rscript it works $ Rscript shebang.r but when I run it from the command line alone $ shebang.r It doesn't work. shebang.r command not found. If I type (based on other examples I've seen) $ ./shebang.r I get permission denied. Yes, Rscript is located in /usr/bin directory Make the file executable. chmod 755 shebang.r In addition to Sjoerd's answer... Only the directories listed in the environment variable PATH are inspected for commands to run. You need to

What's the appropriate Go shebang line?

谁说我不能喝 提交于 2019-12-03 05:31:54
问题 I like using shebangs to run my Perl scripts directly: #!/usr/bin/env perl What's the shebang for Go programs? 回答1: //usr/bin/go run $0 $@ ; exit example: //usr/bin/go run $0 $@ ; exit package main import "fmt" func main() { fmt.Println("Hello World!") } go treat // as a single line comment and shell ignore extra / 回答2: I prefer this: ///bin/true; exec /usr/bin/env go run "$0" "$@" This has several advantages compared to the answer by هومن جاویدپور: Uses 'exec' to replace the new shell

How to make an executable phar?

好久不见. 提交于 2019-12-02 21:14:31
I want to start a phar script as an executable, directly by doing foo.phar <params> instead of php foo.phar <params> . It's easy by modifying the default stub (adding the shebang corresponding to php). // start buffering. Mandatory to modify stub. $phar->startBuffering(); // Get the default stub. You can create your own if you have specific needs $defaultStub = $phar->createDefaultStub('index.php'); // Adding files $phar->buildFromDirectory(__DIR__, '/\.php$/'); // Create a custom stub to add the shebang $stub = "#!/usr/bin/php \n".$defaultStub; // Add the stub $phar->setStub($stub); $phar-

What's the appropriate Go shebang line?

巧了我就是萌 提交于 2019-12-02 19:57:53
I like using shebangs to run my Perl scripts directly: #!/usr/bin/env perl What's the shebang for Go programs? هومن جاویدپور //usr/bin/go run $0 $@ ; exit example: //usr/bin/go run $0 $@ ; exit package main import "fmt" func main() { fmt.Println("Hello World!") } go treat // as a single line comment and shell ignore extra / I prefer this: ///bin/true; exec /usr/bin/env go run "$0" "$@" This has several advantages compared to the answer by هومن جاویدپور: Uses 'exec' to replace the new shell process instead of launching a grandchild process. As a result, your Go program will be a direct child

Shebang/choose what version of Python a script is going to run

丶灬走出姿态 提交于 2019-12-02 10:12:52
问题 As a lot of people I have both the 2.7 and 3.5 version of python. Some code is backwards-compatible, some are not. This is because of the lack of modules that exist for 2.7 but not for 3.5. I therefore have a fair bit of scripts that are 2.7 and a fair bit that are 3.5. The default of .py extensions is the 3.5 version of python in my computer. My question is as follows: How can you "tell" the script to use another version of python(2.7 for instance) rather than the default I am using(3.5). I

“python myscript” ignores “#!/usr/bin/env pythonX” where pythonX doesn't exist

一曲冷凌霜 提交于 2019-12-02 09:38:45
Why doesn't test.py throw error env: python3: No such file or directory when Python 3 is not installed? My system (Mac OS X) has Python 2.7 installed, but not Python 3: $ /usr/bin/env python -V Python 2.7.12 $ /usr/bin/env python3 -V env: python3: No such file or directory File test.py: #!/usr/bin/env python3 import sys print sys.executable Executing test.py: $ python test.py /usr/local/opt/python/bin/python2.7 I thought that since Python 3 does not exist on my system, having the shebang line #!/usr/bin/env python3 will throw an error and terminate the script. But env actually selected the

Shebang/choose what version of Python a script is going to run

这一生的挚爱 提交于 2019-12-02 06:52:12
As a lot of people I have both the 2.7 and 3.5 version of python. Some code is backwards-compatible, some are not. This is because of the lack of modules that exist for 2.7 but not for 3.5. I therefore have a fair bit of scripts that are 2.7 and a fair bit that are 3.5. The default of .py extensions is the 3.5 version of python in my computer. My question is as follows: How can you "tell" the script to use another version of python(2.7 for instance) rather than the default I am using(3.5). I heard about Shebang, but it is Linux only. nekomatic As mentioned in J. F. Sebastian's comment on this

Shebangs in conda managed environments

蓝咒 提交于 2019-12-01 16:34:58
I am trying to write a program in Hy and run it per the instructions on the Quickstart page in the documentation. So I installed Hy using pip from the GitHub repo per the docs, then added executable permissions to the file with chmod +x myfile.hy . To manage my Python environments, I use Anaconda's conda, rather than virtualenv. Hence the shebang #! /usr/bin/env hy does not work for me, since the conda envs live in a different directory. From conda info --envs I see that their directories are myenv * /home/myname/.conda/envs/myenv root /home/myname/anaconda3 Now attempting to run the script

Shebangs in conda managed environments

佐手、 提交于 2019-12-01 15:13:50
问题 I am trying to write a program in Hy and run it per the instructions on the Quickstart page in the documentation. So I installed Hy using pip from the GitHub repo per the docs, then added executable permissions to the file with chmod +x myfile.hy . To manage my Python environments, I use Anaconda's conda, rather than virtualenv. Hence the shebang #! /usr/bin/env hy does not work for me, since the conda envs live in a different directory. From conda info --envs I see that their directories are