本文介绍了将.sh``翻译''为.bat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我想使用这个简单的script.sh:

HI!
I would like to use this simple script.sh:

#!/bin/sh
filename=$1
echo $filename | sed 's/\([A-Z]\)/ \1/g';

在script.bat中,但是我的计算机不是Windows,因此无法对其进行测试.这是正确的吗?

In a script.bat, but my computer is not Windows, so I can't test it. This one would be correct??

prueba.bat 

filename=%1  
echo %filename% | sed 's/\([A-Z]\)/ \1/g';

预先感谢

推荐答案

不完全是

@echo %1| sed "s/\([A-Z]\)/ \1/g"

但是您必须确保有可用的sed( CygWin GnuWin32 非常适合这些工具-如果您只需要特定的东西,我更喜欢GnuWin32,CygWin会给您很多).

But you do have to make sure you have a sed available (CygWin or GnuWin32 are excellent for these tools - I prefer GnuWin32 if you only need specific things, CygWin tends to give you a lot).

您还必须注意filename之类的环境变量. UNIX将在当前shell的上下文中创建它们(因此其作用将受到限制),而cmd.exe脚本将泄漏"它们(因此直接使用%1).

You also have to be careful with environment variables like filename. While UNIX will create them in the context of the current shell (so its effect will be limited), cmd.exe scripts will "leak" them (hence the direct use of %1).

这篇关于将.sh``翻译''为.bat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 04:07