[英]Kubectl with Bash command is always passed in LowerCase and not CamelCase
考虑 Bash 代码:
function dropMyDB() {
kubectl -n $1 exec -ti $1-CLUSSTER-0 -- psql -d MYDBNAME -U postgres -c "truncate table "$2";"
}
dropMyDB $1 "myTableNameInCamelCase"
当我执行它产生的代码时:
ERROR: relation "mytablenameincamelcase" does not exist
command terminated with exit code 1
这意味着表名不是以 CamelCase 形式传递的。
我们如何解决这个问题?
转义你的"$2"
因为它在另一个双引号内
postgres -c "truncate table "$2";"
# to
postgres -c "truncate table $2;"
# or
postgres -c "truncate table \"$2\";"
您可以测试问题不是bash
function dropMyDB() {
echo "kubectl -n $1 exec -ti $1-CLUSSTER-0 -- psql -d MYDBNAME -U postgres -c \"truncate table \"$2\";\""
}
dropMyDB $1 "myTableNameInCamelCase"
然后
chmod +x script.sh
./script.sh foo
kubectl -n foo exec -ti foo-CLUSSTER-0 -- psql -d MYDBNAME -U postgres -c "truncate table "myTableNameInCamelCase";"
IMO 这不是 kubectl 的错:
fun(){ k exec aaaaaaaaaaaaa -it -- echo "$1"; }
fun AdsdDasfsFsdsd
AdsdDasfsFsdsd
但可能是 psql 的,试试这样:
... psql -d MYDBNAME -U postgres -c "truncate table '$2';"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.