Setting a variable in a stream of commands

can someone help me with this?

AgentDX=/tmp/tesfinal && cat final.enc | openssl aes-128-cbc -a -d -salt -k hello | sh

the content of final.enc is a code. and in that code, the value of AgentDX is needed. however, i cant seem to find a way to allow the code to recognize that the variable exist. any ideas?

export AgentDX="/tmp/testfinal"
1 Like

You're assumption is that final.enc can be run through a layer of evaluation.... so I'll stick with that assumption.... (and it's a big assumption!)

finalenc=`cat final.enc`
AgentDX=/tmp/tesfinal
eval echo "${finalenc}" | openssl aes-128-cbc -a -d -salt -k hello | sh

To avoid the evaluation, maybe a substitution would be better on the stream.
It would help (IMHO) if the AgentDX instead of being $AgentDX in final.enc , if instead it were ${AgentDX}. That's just a bit safer/easier on the parse.

then you could have:

AgentDX=/tmp/tesfinal
sed "s;\${AgentDX};${AgentDX};g" final.enc | openssl ... etc...
1 Like

Hmmm - I'm a bit confused - but, openssl seems to read from stdin, so how about

< final.enc AgentDX=/tmp/tesfinal openssl aes-128-cbc -a -d -salt -k hello | sh
1 Like

Perhaps I'm not understanding the OP, but I think the AgentDX the OP wants substituted is inside of the final.enc file, which is why you'd either need to force a round of eval on the content or use something else to substitute the desired value.

1 Like