Linux shell `#!` interpreter All In One

Linux shell #! interpreter All In One

指定腳本解釋器的路徑

Python

Python 3

#!/usr/bin/env python3

# ✅ 推薦寫法, 動態讀取 env 配置的解釋器路徑,切換系統環境不會報錯,可移植性高 🚀 

#!/usr/bin/python3

# 👎 不推薦寫法,寫死了解釋器路徑,切換系統環境有可能會報錯,可移植性低 

image

https://www.runoob.com/python3/python3-tutorial.html

GPIO

#!/usr/bin/env python3

# coding: utf8

import RPi.GPIO as GPIO

import time
import sys

arg1 = sys.argv[1]

print("arg1 =", arg1);

# 指定 BCM 模式下的GPIO 針腳編號
PIN = 12
# BCM 模式
GPIO.setmode(GPIO.BCM)

# 指定 GPIO 針腳爲一個電流輸出針腳
GPIO.setup(PIN, GPIO.OUT)

# 輸出低電平
GPIO.output(PIN, GPIO.LOW)

# index
i = 0
# max
# n = 7

# 類型轉換,str => int
n = int(arg1)

print("n =", n)

print('開始閃爍⏳')

while (i < n):
    print("i =", i)
    # 高電平,LED 點亮
    GPIO.output(PIN, GPIO.HIGH)
    # 休眠 1 秒,防止 LED 長時間點亮燒壞了
    time.sleep(1.0)
    # 低電平,LED 熄滅
    GPIO.output(PIN, GPIO.LOW)
    # 休眠 1 秒
    time.sleep(1.0)
    i = i + 1

# 輸出低電平,LED 關閉
# GPIO.output(PIN, GPIO.LOW)

# 清除,釋放內存
GPIO.cleanup()

print('結束閃爍 👌🏻')


Node.js CLI

#!/usr/bin/env node

# ✅ 推薦寫法, 動態讀取 env 配置的解釋器路徑,切換系統環境不會報錯,可移植性高 🚀 

#!/usr/bin/node

# 👎 不推薦寫法,寫死了解釋器路徑,切換系統環境有可能會報錯,可移植性低 

cli

#!/usr/bin/env node

/**
 * [nct : node cli tools]
 * @author: xgqfrms
 * @date: 2017-06-12
 */

const nct = require('./libs');

const username = process.argv[2] || `xgqfrms-GitHub`;
const repo = process.argv[3] || `Node-CLI-Tools`;

nct(username, repo);

https://github.com/xgqfrms-GitHub/Node-CLI-Tools

https://node-cli-tools.xgqfrms.xyz/

(🐞 反爬蟲測試!打擊盜版⚠️)如果你看到這個信息, 說明這是一篇剽竊的文章,請訪問 https://www.cnblogs.com/xgqfrms/ 查看原創文章!

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 發佈文章使用:只允許註冊用戶纔可以訪問!

原創文章,版權所有©️xgqfrms, 禁止轉載 🈲️,侵權必究⚠️!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章