设置环境变量 [英] Setting an environment variable

查看:198
本文介绍了设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用XP。我在使用变量面临的问题。

I am using xp. I am facing problem in using Variables.

我使用以下code

@echo关闭
集VAR =srting

@echo off set var = "srting"

当我使用%检查变量的值

When i check the value of var using %

设置%VAR%

没有定义的环境变量VAR%%

Environment variable %var% not defined

任何帮助...

推荐答案

如果您要执行基于文件内容不同code路径,这应该为你工作:

If you want to execute different code path based on file content, this should work for you:

@echo off
set FILE_CONTENT=string

for /f %%a in (file.txt) do set var=%%a

if %var%==%FILE_CONTENT% (
 goto MATCHED
 ) else (
     goto NOT_MATCHED
     )

 :MATCHED
 echo "matched"
 goto:EOF

 :NOT_MATCHED
 echo "Not matched"
 goto:EOF

但是,如果文件名包含空格'像' C:\\ Program Files文件(x86)的',上面的code将无法正常工作的解决方法是获取短名称(可能使用:〜dpsx)的文件,然后使用吧。

However, if the file name contains 'spaces' or '(' like in 'c:\program files(x86)', the above code will not work. The workaround is to get the short name (probably using: ~dpsx) of the file and then use it.

这篇关于设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆