Kubectl with Bash command is always passed in LowerCase and not CamelCase


Consider the Bash code:

function dropMyDB() {
  kubectl -n $1 exec -ti $1-CLUSSTER-0 -- psql -d MYDBNAME -U postgres -c "truncate table "$2";"

dropMyDB $1 "myTableNameInCamelCase"

When I execute the code it produces:

ERROR:  relation "mytablenameincamelcase" does not exist
command terminated with exit code 1

Which means that the table name is not passed in its CamelCase form.

How can we fix this ?



Escape your "$2" because it is inside another double quote

postgres -c "truncate table "$2";"

# to
postgres -c "truncate table $2;"

# or
postgres -c "truncate table \"$2\";"


You can test that the issue is not

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";"

Answered By – Shakiba Moshiri

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published