小编Bal*_*eue的帖子

批量测试变量是否等于空格

在我的代码中,我循环遍历字符串中的每个字符。我需要测试字符是否为空格。

这是我的代码:

if %str% == " " (
    ::echo Empty
    echo | set /p=%space%
    goto loopEnd
)
Run Code Online (Sandbox Code Playgroud)

我也试过:

if [%str%] == [" "] (
    ::echo Empty
    echo | set /p=%space%
    goto loopEnd
)
Run Code Online (Sandbox Code Playgroud)

两者都给出错误

( was unexpected at this time.
Run Code Online (Sandbox Code Playgroud)

或者

] was unexpected at this time.
Run Code Online (Sandbox Code Playgroud)

我在测试字母或数字时不会出错。我究竟做错了什么?

谢谢,

扎克

windows batch-file

7
推荐指数
1
解决办法
2480
查看次数

在 if 语句中使用 pgrep 命令

我需要一个 .sh 文件,如果我的 python 服务未运行,它将回显 0。我知道这pgrep是我想要使用的命令,但我在使用它时遇到错误。

if [ [ ! $(pgrep -f service.py) ] ]; then
    echo 0
fi
Run Code Online (Sandbox Code Playgroud)

这是我在网上找到的,但我一直收到错误

./test_if_running.sh: line 3: syntax error near unexpected token `fi'
./test_if_running.sh: line 3: `fi;'
Run Code Online (Sandbox Code Playgroud)

当我打字时

./test_if_running.sh
Run Code Online (Sandbox Code Playgroud)

linux bash sh

2
推荐指数
2
解决办法
8231
查看次数

标签 统计

bash ×1

batch-file ×1

linux ×1

sh ×1

windows ×1