[英]shell script to pass argument to input file
我有 shell 腳本,它從用戶那里獲取一些輸入並將該輸入傳遞給我在 shell 腳本中使用的文件
Shell 腳本myscript.sh
kubectl create -f de_pod.yaml
這是de_pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
restartPolicy: Never
containers:
- name: run-esp
image: myimage:1
command: ["python", "/script.py", "$Input1", "$input2"]
imagePullPolicy: Always
stdin: true
tty: true
這就是我運行腳本的方式
sh myscript.sh my1stinput my2ndinput
如果您查看de_pod.yaml
在 line command: ["python", "/script.py", "$Input1", "$input2"]
這里我在運行myscript.sh
后使用用戶輸入。 但$input1
和$input2
都沒有填充我的值
我做錯了什么?
不是最好的解決方案,但如果您想以這種方式使用 pod 部署,那么它應該可以工作。 生成不同參數的yaml文件,通常使用Helm圖表
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
restartPolicy: Never
containers:
- name: run-esp
image: myimage:1
command: ["python", "/script.py", "input1", "input2"]
imagePullPolicy: Always
stdin: true
tty: true
kubectl create -f de_pod.yaml | sed "s/input1/$1/g" | sed "s/input2/$2/g"
我懷疑你想要的是這樣的。
myscript.sh :
#!/bin/bash
[[ "${#}" -ne 2 ]] && {
echo "Usage: ${0} <something_something> <something_else>" 1>&2;
exit 1;
};
template="/path/to/de_pod.yaml";
my1stinput=""; printf -v my1stinput '%q' "${1}";
my2ndinput=""; printf -v my2ndinput '%q' "${2}";
sed -e "s/\$Input1/${my1stinput}/g" -e "s/\$Input2/${my2ndinput}/g" "${template}" | kubectl create -f - ;
如果 2 arguments 中的值是復數,那么應該額外考慮確保它們在sed
模式中正確轉義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.