从shell命令中删除空格

时间:2018-10-15 10:18:43

标签: shell batch-file certutil

我正在开发执行命令的Shell脚本,并返回校验和字符串。该字符串的每个六边形都用空格隔开,我想删除该字符串,并使用例如4AA512代替4A A5 12作为命令输出,但是我找不到有效的解决方案。这里是脚本:

for /f  "delims=" %%f in ('dir %~dp0*.zip /b') do (
    echo %%~f:
    for /f "delims=" %%a in ('certUtil -hashfile "%~dp0%%~f" SHA512 ^| find /i /v "SHA512" ^| find /i /v "certUtil"^') do (
          echo %%a:' '=''%
        )

    set /a counter += 1
    echo.
 )

有人解决吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

(答案从问题/评论移至-很好-一个答案)

最终找到了解决方案:

set counter=0
for /f  "delims=" %%f in ('dir %~dp0*.zip /b') do (
    echo %%~f:
    for /f "delims=" %%a in ('certUtil -hashfile "%~dp0%%~f" SHA512 ^| find /i /v "SHA512" ^| find /i /v "certUtil"^') do (call :ShowChecksum "%%a")
    set /a counter += 1
    echo.
)

echo %counter% files(s) found.
pause
exit

:ShowChecksum
set "checksum=%~1"
set "checksum=%checksum: =%"
echo %checksum%