2
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-04-24

どうもこんばんは、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にも描きたくなったので書きました
見てくださりありがとうございます。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0