pg_restore命令不接受文件名作为变量。

huangapple go评论61阅读模式
英文:

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

这是在读取 dbName 文件时出现的错误:

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

当我尝试回显 $latest 时,它可以工作,但在 pg_restore 命令中不起作用。对此有任何帮助将不胜感激。

英文:
$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

答案1

得分: 1

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"

英文:

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"

huangapple
  • 本文由 发表于 2023年5月10日 19:21:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76217788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定