bash - 寻找匹配的 `'时出现意外的EOF

标签 bash powershell docker shell scripting

我在脚本下运行并出现错误

#!/bin/bash
webproxy="webproxy-test-01"
webproxycurl="curl -k -s https://localhost:\${nginx_https_port}/HealthCheckService"
sudo docker exec $webproxy sh -c \'$webproxycurl\'
这是错误。
-k: -c: line 0: unexpected EOF while looking for matching `''
-k: -c: line 1: syntax error: unexpected end of file
这是在shell提示符下起作用的命令
$sudo docker exec webproxy-test-01 sh -c 'curl -k -s https://localhost:${nginx_https_port}/HealthCheckService'
HEALTHCHECK_OK
有人可以帮我解决这个错误。任何帮助将不胜感激。

最佳答案

尝试使用:

sudo docker exec $webproxy sh -c "$webproxycurl"
另外,请注意,请勿在sudo中运行docker。
  • 添加docker组(如果尚不存在):
     sudo groupadd docker
    
  • 将连接的用户“$ USER”添加到docker组。如果您不想使用当前用户,请更改用户名以匹配您的首选用户:
     sudo gpasswd -a $USER docker
    
  • 执行newgrp docker或注销/登录以激活对组的更改。
  • 您可以使用
     docker run hello-world
    
    检查是否可以在没有sudo的情况下运行docker。

  • 检查this answer以获得更多详细信息。

    关于bash - 寻找匹配的 `'时出现意外的EOF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63644875/

    相关文章:

    linux - 通过 cURL 远程执行 Bash 脚本

    bash - 需要一个 bash 脚本来自动将文件移动到子文件夹

    bash - sed、awk、grep 匹配单词 2 个文件

    Powershell 脚本将新文件夹创建为 @{Folder=Test-folder}/

    powershell [System.IO.File]::WriteAllLines 不工作

    python - 如何正确缓存 Python 依赖项

    bash - shell 脚本是否可以指示其行最初已加载到内存中?

    powershell - 使用Powershell写出两个标题行而不删除现有数据

    docker - Visual Studio Team Service 失败任务 Docker 构建

    azure - 如何从 Azure DevOps 管道运行 "docker login azure"