假设我想跑步
>foo bar但是bar随我在文件系统中的位置而变化.我想做的就是不必记住bar的正确值,就是将文件fizz保留在各自的文件夹中,以便我可以执行类似call
but bar changes depdending on where I am in my filesystem. What I'd like to do, so I don't have to remember the proper value of bar, is to keep a file fizz in the respective folders so I can do something like call
>foo fizz这当然是开箱即用的.
which of course doesn't work out of the box. Neither does
>foo < fizz因为foo不希望输入,只是一个参数.我找到了 Linux解决方案,但没有找到Windows.
because foo doesn't expect input, just a parameter. I found a solution for Linux, but nothing for Windows.
推荐答案假设fizz包含单行且无空格,即单线
Assuming fizz contains a single line with no whitespace, the one-liner
for /F %i in (fizz) do @foo %i将做您想要的.如果您要放入fizz的参数可能包含空格,请使用
will do what you want. If the argument you're putting into fizz may contain whitespace, use
for /F "delims=" %i in (fizz) do @foo "%i"一次传递参数.如果将%字符放入批处理文件中,则将其加倍.
to pass the argument in one piece. Double the % characters if putting this into a batch file.
更多推荐
如何在命令行中将文件内容作为参数传递?
发布评论