Native shebang: Difference between revisions
Content added Content deleted
m (Clarify: this task must be done in the specimen language, '''neither''' using a shell script '''nor''' any other 3rd language.) |
m (Make it so that all that is required is a custom shebangs at the start of the ''test case''. e.g. "#!/usr/local/bin/script_foo") |
||
Line 1: | Line 1: | ||
{{draft task|Basic language learning}} |
{{draft task|Basic language learning}} |
||
'''In short:''' Use the specimen language for "scripting". |
'''In short:''' Use the specimen language (native) for "scripting". |
||
⚫ | |||
⚫ | |||
'''In long''': Create a program (in the specimen language) that will automatically compile a ''test case'' (of the same specimen language) to a native binary executable and then transparently load and run this ''test case'' executable. |
'''In long''': Create a program (in the specimen language) that will automatically compile a ''test case'' (of the same specimen language) to a native binary executable and then transparently load and run this ''test case'' executable. |
||
Make it so that all that is required is a custom [[wp:Shebang (Unix)|shebangs]] at the start of the ''test case''. |
Make it so that all that is required is a custom [[wp:Shebang (Unix)|shebangs]] at the start of the ''test case''. e.g. "<tt>#!/usr/local/bin/script_foo</tt>" |
||
'''Importantly:''' This task must be coded '''strictly''' in the specimen language, '''neither''' using a shell script '''nor''' any other 3rd language. |
'''Importantly:''' This task must be coded '''strictly''' in the specimen language, '''neither''' using a shell script '''nor''' any other 3rd language. |
||
Line 13: | Line 14: | ||
Note: If the lauguage (or a specific implementation) handles this automatically, then simple provide an example of "echo.foo" |
Note: If the lauguage (or a specific implementation) handles this automatically, then simple provide an example of "echo.foo" |
||
'''Background:''' |
'''Background:''' |
||
Line 18: | Line 20: | ||
Simple [[wp:Shebang (Unix)|shebangs]] can help with scripting, e.g. "<tt>#!/usr/bin/env python</tt>" at the top of a [[Python]] script will allow it to be run in a terminal as "./script.py". |
Simple [[wp:Shebang (Unix)|shebangs]] can help with scripting, e.g. "<tt>#!/usr/bin/env python</tt>" at the top of a [[Python]] script will allow it to be run in a terminal as "./script.py". |
||
The task [[Multiline shebang]] largely demonstrates how to use "shell" code in the shebang to compile and/or run source-code from a 3rd language. |
The task [[Multiline shebang]] largely demonstrates how to use "shell" code in the shebang to compile and/or run source-code from a 3rd language, typically "<tt>#!/bin/bash</tt>" or "<tt>#!/bin/sh</tt>". |
||
'''This task:''' |
'''This task:''' |
||
Line 38: | Line 41: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
===Using ALGOL 68G to script ALGOL 68G=== |
|||
{{works with|ALGOL 68|Revision 1.}} |
{{works with|ALGOL 68|Revision 1.}} |
||
{{works with|ALGOL 68G|Any - Tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.7 algol68g-2.7].}} |
{{works with|ALGOL 68G|Any - Tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.7 algol68g-2.7].}} |
||
Line 56: | Line 60: | ||
=={{header|C}}== |
=={{header|C}}== |
||
===Using gcc to script C=== |
|||
'''File: script_gcc.c''' |
'''File: script_gcc.c''' |
||
<lang c>#!/usr/local/bin/script_gcc.sh |
<lang c>#!/usr/local/bin/script_gcc.sh |
||
Line 209: | Line 214: | ||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
===Using sh to script sh=== |
|||
In strictly shell this is natural, native and easy. |
|||
'''File: echo.sh''' |
|||
<lang sh>#!/bin/sh |
|||
echo "$@"</lang> |
|||
'''Usage:''' |
|||
<pre> |
|||
./echo.sh Hello, world! |
|||
</pre> |
|||
'''Output:''' |
|||
<pre> |
|||
Hello, world! |
|||
</pre> |
|||
===Using bash to script C=== |
|||
{{works with|Bourne Again SHell}} |
{{works with|Bourne Again SHell}} |
||
Note: this '''Native shebang''' task does not exactly apply to [[bash]] because bash is interpretive, but as a skeleton template the following script is an example of how compiled languages can implement the shebang. Also: this bash code can be used to ''automatically'' compile the C code in /usr/local/bin/script_gcc.c above. |
Note: this '''Native shebang''' task does not exactly apply to [[bash]] because bash is interpretive, but as a skeleton template the following script is an example of how compiled languages can implement the shebang. Also: this bash code can be used to ''automatically'' compile the C code in /usr/local/bin/script_gcc.c above. |
||
Line 303: | Line 326: | ||
=={{header|python}}== |
=={{header|python}}== |
||
{{incorrect|python|specimen uses /usr/bin/env to locate the python implementation, but env is written in C}} |
|||
Extract: "If you need to create a .pyc file for a module that is not imported, you can use the py_compile and compileall modules. The py_compile module can manually compile any module. One way is to use the py_compile.compile function in that module interactively:[http://effbot.org/pyfaq/how-do-i-create-a-pyc-file.htm]:" |
Extract: "If you need to create a .pyc file for a module that is not imported, you can use the py_compile and compileall modules. The py_compile module can manually compile any module. One way is to use the py_compile.compile function in that module interactively:[http://effbot.org/pyfaq/how-do-i-create-a-pyc-file.htm]:" |
||
<pre> |
<pre> |
||
Line 311: | Line 336: | ||
'''File: echo.py''' |
'''File: echo.py''' |
||
<lang python>#!/usr/bin/env python |
<lang python>#!/usr/bin/env python |
||
# -*- coding: utf-8 -*- |
|||
import sys |
import sys |
||
print " ".join(sys.argv[1:])</lang> |
print " ".join(sys.argv[1:])</lang> |