Search code examples
postgresqlbashshellpg-restore

pg_restore command is not accepting filename as variable


$latest = 'filename.sql'  
kubectl exec -n testnamspace pod/test-- sh -c 'PGPASSWORD=ss pg_restore --clean -h postgresql -p 5432 -U test_user -d dbName -F c /tmp/$latest'

This is the error I am getting while reading dbName file:

pg_restore: error: could not open input file "$/tmp/": No such file or directory

When I try to echo $latest, it is working but not with pg_restore command. Any help in this regard would be appreciated


Solution

  • try using double quotes

    kubectl exec -n testnamspace pod/test -- sh -c "PGPASSWORD=ss pg_restore --clean -h postgresql -p 5432 -U test_user -d dbName -F c /tmp/$latest"
    

    or

    latest='filename.sql'
    command="PGPASSWORD=ss pg_restore --clean -h postgresql -p 5432 -U test_user -d dbName -F c /tmp/$latest"
    kubectl exec -n testnamspace pod/test -- sh -c "$command"