说我有一个文件/templates/apple,我想
所以,/templates/apple将被复制到/templates/usedAND /templates/inuse
然后之后我想删除原始.
是cp最好的方法,然后rm呢?或者,还有更好的方法?
我想在一行中完成所有操作,所以我认为它看起来像:
cp /templates/apple /templates/used | cp /templates/apple /templates/inuse | rm /templates/apple
Run Code Online (Sandbox Code Playgroud)
这是正确的语法吗?
我想弄清楚什么时候管道 或重定向<>在命令中优先?
这是我的想法,但需要确认这是它的工作原理.
例1:
sort < names | head
The pipe runs first: names|head then it sorts what is returned from names|head
Run Code Online (Sandbox Code Playgroud)
例2:
ls | sort > out.txt
This one seems straight forward by testing, ls|sort then redirects to out.txt
Run Code Online (Sandbox Code Playgroud)
例3:
Fill in the blank? Can you have both a < and a > with a | ???
Run Code Online (Sandbox Code Playgroud) 我试图通过使用ADD_CUSTOM_COMMAND向我的vc2010项目添加一些自定义构建命令.但:
[1]我发现CMAKE会自动插入比我预期更多的代码.
例如,我希望命令完全是:
"c:\Some Folder\MyTool.exe" -arg0 -arg1
Run Code Online (Sandbox Code Playgroud)
CMakeLists.txt中的相应代码如下:
add_custom_command( OUTPUT ${outfile}
COMMAND "c:\Some Folder\MyTool.exe" ARGS "-arg0 -arg1"
# COMMAND "\"c:\Some Folder\MyTool.exe\"" will FAIL to be parsed!
MAIN_DEPENDENCY ${infile}
VERBATIM)
Run Code Online (Sandbox Code Playgroud)
但实际上我得到了:
setlocal
c:\Some Folder\MyTool.exe "-arg0 -arg1"
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
Run Code Online (Sandbox Code Playgroud)
这不是我想要的.我也尝试过字符串:COMMAND "\"${MYTOOL_PATH}\" -arg0 -arg1"但是CMake只是无法解析它,因为字符串前面有一个引号.所以很糟糕我不能引用命令字符串,因为路径c:\Some Folder\MyTool.exe包含空格.
[2]我还注意到CMake会自动扩展我的依赖性修补程序.
如果我添加到命令DEPENS "$(PATH_MACRO)" …
add_custom_command()在构建 elf 文件目标后,我在 CMake 构建中有一些东西可以做一些事情:将其转换为 srec,用 0xFF 填充各个区域并创建一个二进制图像,生成一个 CRC 并获取图像的大小。 add_custom_command()可以有DEPENDS,让它只在elf文件重新生成时才运行,很棒。
我还想做的是使用 FILE() 创建一个新文件,其中包含二进制文件名、crc 和大小(可能是简单的 JSON 格式),但文档暗示我不能在事情之后做这个文件活动我上面提到的已经发生了。
# This command creates the FF-filled binary file. It uses objcopy to create the srec
# file to operate on.
add_custom_command(
OUTPUT ThreadingApp.bin filled.srec
MAIN_DEPENDENCY ThreadingApp.elf
COMMAND ${CMAKE_OBJCOPY} ARGS -O srec ThreadingApp.elf ThreadingApp.srec
COMMAND srec_cat.exe ThreadingApp.srec -offset - -minimum-addr ThreadingApp.srec
?fill 0xFF -over ThreadingApp.srec -o filled.srec
COMMAND srec_cat.exe filled.srec -o ThreadingApp.bin -binary
)
# This command creates the CRC …Run Code Online (Sandbox Code Playgroud)