pct exec export var.

Xilmen

Active Member
Mar 30, 2017
26
0
41
35
Hello everyone,
I need to do an export of a varibale in a LXC centos containers. After a few tests I notice that the values it returns for this varibale is an empty field.

Here is the test that I made :

Code:
root@srv-proxmox:[~]:# pct exec 302 -- bash -c "TMP=hi; echo $TMP"

root@srv-proxmox:[~]:#


The command that I really want to pass is the one :

Code:
pct exec 302 -- bash -c "IP=$(echo 192.168.2.222 | sed 's/^.*\.\([^.]*\)$/\1/') ; sed -i '/; PTR Records/a'$IP'    IN    PTR  try1\.lan\. ; 192.168.2.222' /etc/named/zones/db.lan.inv"
 
that has nothing to do with pct. what you are actually passing to pct is the command
Code:
TMP=hi; echo
because your shell will expand all the variables inside the double quotes, and TMP is not set/empty in your shell. you need to use single quotes or escape the special characters like $:
Code:
# pct exec 100 -- bash -c 'TMP=hi; echo $TMP'
hi
Code:
# pct exec 100 -- bash -c "TMP=hi; echo \$TMP"
hi
 
ty a lot :)

my command :

Code:
pct exec 302 -- bash -c "IP=$(echo 192.168.2.222 | sed 's/^.*\.\([^.]*\)$/\1/') ; sed -i '/; PTR Records/a'\$IP'    IN    PTR  try1\.lan\. ; 192.168.2.222' /etc/named/zones/db.lan.inv"

work's fine !