【发布时间】:2020-10-29 15:49:55
【问题描述】:
我需要一个等效的 Unix shell 脚本:
#!/bin/bash
# save incoming YAML to file
cat > all.yaml
# modify the YAML with kustomize
kustomize build . && rm all.yaml
但对于 Windows。我最终得到:
@echo off
type > all.yaml
kustomize build .
但它不起作用 - 生成的文件是空的。我请求帮助。
Command cat > all.yaml 获取标准输出并将其存储在 all.yaml 文件中。 Helm 对 std in/out 和 Kustomize 文件进行操作,因此此脚本可确保此工具之间的正确通信。提供给 helm 的脚本如下:helm upgrade <release_name> <chart> --post-renderer kustomize(脚本保存在文件 kustomize 中)。
编辑
简化我寻找与 Unix 等效的 Windows:
whoami | cat > file.txt
【问题讨论】:
-
这是您在运行该批处理文件时遇到的错误:
The syntax of the command is incorrect.。这来自TYPE命令,因为您没有向它提供要输出的文件。如果您查看帮助,它清楚地定义了文件名不是可选的。TYPE [drive:][path]filename. -
cat > all.yaml应该做什么? 没有文件,它会读取标准输入。你确定它至少不应该是cat * > all.yaml?,(可能是cat *.yaml > all.yaml)。然后在 Windows 中,你会做类似的事情,type * > all.yaml,(可能是type *.yaml > all.yaml)。如果您的 shell 脚本采用标准输入,那么为了在您的批处理/cmd 脚本中执行相同的操作,您需要有标准输入,而您显然没有告诉我们那是什么,或者实际上是否,有的。 -
抱歉不准确。命令 cat > all.yaml 获取标准输出并将其存储在 all.yaml 文件中。 Helm 对 std in/out 和 Kustomize 文件进行操作,因此此脚本可确保此工具之间的正确通信。提供给 helm 的脚本如下: helm upgrade
--post-renderer kustomize(脚本保存在文件 kustomize 中)。我在 WSL Ubuntu 发行版上对其进行了测试,并且运行良好。 -
您是否使用重定向的 STDIN 运行脚本?喜欢
< file.ext script.bat …,还是program.ext | script.bat …? -
@aschipfl Helm 将脚本作为“后渲染器”运行,但我认为它可能看起来像:
helm template <release_name> <chart> | ./kustomize- 所以,第二个选项。
标签: batch-file sh kubernetes-helm kustomize