【msys2】cygpath:パス表記をWindows/UNIX形式に変換する ==================================================== cygpathコマンドは、Windows形式のパス表記とUNIX(msys)形式のパス表記を相互に変換するためのmsys2専用コマンド。 又、重要なWindowsシステムディレクトリの位置を、Windows形式あるいはUNIX形式のいずれかで取得することもできる。 ### 書式1 ``` $ cygpath (-d|-m|-u|-w|-t 種類) [-c ハンドル] [-f ファイル名] [オプション] パス名 ``` ### 書式2 ``` $ cygpath [-ADHPSW] [-d|-m|-u-w] ``` 出力形式の変換を行う際は、msys2のマウント情報に従ってディレクトリの読み替えを行う。なお、cygpathコマンドは指定したファイルが存在するか否かの確認はせず、与えられたファイル名やパスをオプションにしたがって変換するだけ。 主なオプション ------------- ### 出力タイプのオプション ^オプション ^説明 ^ |`-d, --dos` |パス名をDOS(短縮)形式で表示(`C:¥PROGRA~1`)する | |`-m, --mixed` |`--windows`オプションに似ているが、「`¥`」の代わりに「`/`」を使用する(`C:/WINNT`) | |`-u, --unix` |パス名をUNIX形式(`/c/WINNT`)で表示する(デフォルトの動作) | |`-w, --windows` |パス名をWindows形式で表示する(`C:¥WINNT`) | |`-t, --type 形式`|パス名を指定された形式(dos/mixed/unix/windows)で表示する | ### パス変換のオプション ^オプション ^説明 ^備考 ^ |`-a, --absolute` |絶対パスで出力する | | |`-l, --long-name` |パス名をWindowsの長い形式で表示する |`-w`,`-m`オプションとだけ併用可能 | |`-p, --path` |パス名を、たとえば`/bin:/usr/bin`のような「パスのリスト」として扱う | | |`-s, --short-name`|パス名をDOS(短縮)形式で表示する |`-w`,`-m`オプションとだけ併用可能 | ### システム情報オプション ^オプション ^説明 ^ |`-D, --desktop` |`Desktop`ディレクトリの表示 | |`-O, -- mydocs` |`My Documents`ディレクトリの表示 | |`-S, --sysdir` |システムディレクトリの表示 | |`-W, --windir` |`Windows`ディレクトリの表示 | ### その他のオプション ^オプション ^説明 ^ |`-h, --help` |使い方(ヘルプ)を表示 | |`-V, --version` |バージョン情報を表示 | 実行例 ----- ### UNIX形式に変換 ``` $ cygpath -u "C:\work\t-kernel" /c/work/t-kernel ``` ### Windows形式に変換 ``` $ cygpath -w "/c/work/t-kernel" C:\work\t-kernel ``` ### Windowsディレクトリの表示 ``` $ cygpath -W /c/Windows ``` ### makefileの中で利用 $BD変数をUNIX形式に変換 ``` BD := $(shell /usr/bin/cygpath -u $(BD)) ``` ### シェルスクリプトで利用 $BD変数をUNIX形式に変換 BD=`cygpath -u $(BD)` ### バージョン情報表示 ``` $ cygpath --version cygpath (cygwin) 2.7.0 Path Conversion Utility Copyright (C) 1998 - 2017 Cygwin Authors This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ``` ### ヘルプ表示 ``` $ cygpath --help Usage: cygpath (-d|-m|-u|-w|-t TYPE) [-f FILE] [OPTION]... NAME... cygpath [-c HANDLE] cygpath [-ADHOPSW] cygpath [-F ID] Convert Unix and Windows format paths, or output system path information Output type options: -d, --dos print DOS (short) form of NAMEs (C:\PROGRA~1\) -m, --mixed like --windows, but with regular slashes (C:/WINNT) -M, --mode report on mode of file (binmode or textmode) -u, --unix (default) print Unix form of NAMEs (/cygdrive/c/winnt) -w, --windows print Windows form of NAMEs (C:\WINNT) -t, --type TYPE print TYPE form: 'dos', 'mixed', 'unix', or 'windows' Path conversion options: -a, --absolute output absolute path -l, --long-name print Windows long form of NAMEs (with -w, -m only) -p, --path NAME is a PATH list (i.e., '/bin:/usr/bin') -U, --proc-cygdrive Emit /proc/cygdrive path instead of cygdrive prefix when converting Windows path to UNIX path. -s, --short-name print DOS (short) form of NAMEs (with -w, -m only) -C, --codepage CP print DOS, Windows, or mixed pathname in Windows codepage CP. CP can be a numeric codepage identifier, or one of the reserved words ANSI, OEM, or UTF8. If this option is missing, cygpath defaults to the character set defined by the current locale. System information: -A, --allusers use `All Users' instead of current user for -D, -O, -P -D, --desktop output `Desktop' directory and exit -H, --homeroot output `Profiles' directory (home root) and exit -O, --mydocs output `My Documents' directory and exit -P, --smprograms output Start Menu `Programs' directory and exit -S, --sysdir output system directory and exit -W, --windir output `Windows' directory and exit -F, --folder ID output special folder with numeric ID and exit Other options: -f, --file FILE read FILE for input; use - to read from STDIN -o, --option read options from FILE as well (for use with --file) -c, --close HANDLE close HANDLE (for use in captured process) -i, --ignore ignore missing argument -h, --help output usage information and exit -V, --version output version information and exit ``` 参考 ---- 1. [NTEmacs + cygwin or msys2 で exec-path-from-shell](http://qiita.com/KazuSoap/items/ee7a4dec80308dbd1d41) 2. [cygpath の便利なオプション](http://takuya-1st.hatenablog.jp/entry/20110910/1315644196)