以下在我的Dockerfile
中不起作用:
RUN if $SSH_PRIVATE_KEY -eq ""; then echo "SSH key is not set, aborting"; exit 1; else echo "SSH key is set"; fi
我收到以下错误:
Step 4/15 : RUN if $SSH_PRIVATE_KEY -eq ""; then echo "SSH key is not set, aborting"; exit 1; else echo "SSH key is set"; fi
---> Running in 3bd29320f0e3
/bin/sh: -eq: command not found
我想检查
$SSH_PRIVATE_KEY
变量是否包含任何内容。
最佳答案
在变量周围添加引号(如果变量中可能有空格),只需使用=
运算符进行字符串比较即可。
在Bourne shell中,它将是:
if [ "$SSH_PRIVATE_KEY" = "" ]; then echo "SSH key is not set, aborting"; exit 1; else echo "SSH key is set"; fi
关于docker - Dockerfile变量的if else子句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48869814/