私はcmd.exeに苦労しているので、これをコードに入れましょう:
:: Set an environment variable var to `pwd`
:: (forget about the backslashes)
C:\somedir>set var=C:\\\somedir\\\ & call echo %var%
C:\\\somedir\\\
:: great! works.
:: Is the environment variable really there?
C:\somedir>set v
var=C:\\\somedir\\\
:: yes. ok.
:: Traverse directory recursively, find class files ending with T,
:: delete `pwd` from filenames:
C:\somedir>dir /s /b *T.class | grep T\. | sed 's/%var%//g'
C:\somedir\domain\test\ClassT.class
:: uh oh no! Didn't work.
:: Wait a minute. Is the environment variable really there?
C:\somedir>set v
var=C:\\\somedir\\\
:: hmm...yes, indeed?
:: ok. Take a breath. Start over. Empty/Delete var.
C:\somedir>set var=
:: Manually fill var
C:\somedir>set var=C:\\\somedir\\\
:: Try again...
C:\somedir>dir /s /b *T.class | grep T\. | sed 's/%var%//g'
domain\test\ClassT.class
::YES! uh...oh...no...w**hy does it not work above?
問題は、環境で使用できるにもかかわらずパイプラインで使用できない理由と、var
var を「手動で」設定すると何が変更されるかということですset var=C:\\\somedir\\\ & call echo %var%
。 .