开发者

Can I store the output of a command in a variable in batch scripting?

开发者 https://www.devze.com 2023-03-19 00:43 出处:网络
I want to dir a folder and get in a variable all the names 开发者_运维百科of the *.csv files. Does anyone know how can I do this?Using Bash you can try:

I want to dir a folder and get in a variable all the names 开发者_运维百科of the *.csv files.

Does anyone know how can I do this?


Using Bash you can try:

dirlist=`ls -1 *.csv`
echo "$dirlist"

Under windows you can read the following Q and A:

Windows batch files: How to set a variable with the result of a command?

Something like:

for /f "delims=" %%a in ('dir') do @set foobar=%%a

Change 'dir' to what you want. I have no windows machine close by, so cannot test.


I apologize for a duplicate response, but StackOverflow has reputation counters that impede me from certain actions.

When executing directly on the command-prompt, use the following form:

for /f "delims=" %a in ('whoami') do @set myaccount=%a

The form in previous answer is intended when used in a .bat or .cmd file.

0

精彩评论

暂无评论...
验证码 换一张
取 消