BATファイルにシェルスクリプトを埋め込む方法
Bash on Ubuntu on Windowsによって、Windowsでカジュアルにbashを利用することが出来るようになりましたよね。 しかしながらシェルスクリプトを直接実行することはできないようです。(パスの形式が違うので関連付けで実行できない)
ということで、BATファイルに埋め込めるようにしてみました。
# ———- SHELL ———- #
以降に実行したいシェルスクリプトを記述します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@rem ' | |
@echo off | |
set P="/mnt/%~f0" | |
set P=%P:\=/% | |
set P=%P::=% | |
set P=%P:/mnt/C/=/mnt/c/% | |
set P=%P:/mnt/D/=/mnt/d/% | |
bash.exe %P% %* | |
goto :eof | |
' 2>/dev/null | |
# ---------- SHELL ---------- # | |
echo \$1 = $1 | |
yes This is ShellScript | head -3 | |
※改行コードはLFにしておく必要があります。
実行結果

こんな感じで引数も渡せます。