Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8930

nodejsやpythonのファイルの最初の行にシェルスクリプトで使われる「あれ」を付けて実行ファイル化してみよう

$
0
0

どうもこんばんは、cedです。
今回はlinux系で使われるシェルスクリプトの「あれ」をnodejsやpythonのファイルにつけて実行してみようっていう記事です。

※これはwindowsでする場合、WSLが必要になります。

実行環境

os: ubuntu 19.10 / arm64(Android)
python: 3.7.5
nodejs: 12.16.2

さっそくHello Worldを書いてみる

の前にファイルに権限与える

nodejs
touch index.js
chmod +x index.js
python
touch index.py
chmod +x index.py

nodejsの場合

index.js
#!/usr/local/bin/node
//nでインストールしていない場合はlocalは要らないconsole.log("Hello Woeld!");

pythonの場合

index.py
#!/usr/bin/python3
print("Hello Woeld!");

結果

Screenshot_20200424-194424_Termux.jpg

終わりに

個人的にこの方法出来るのが嬉しくて記事にしました。
noteでも同じようなやつを書きましたが、qiitaにも描きたくなったので書きました
見てくださりありがとうございます。


Viewing all articles
Browse latest Browse all 8930

Trending Articles