Skip to content
Advertisement

preserve inline variable with sudo

Hi i’m trying to make something like this to work in bash

JavaScript

but i keep getting an empty line, the only thing that works so far is:

JavaScript

what i would like to achieve is the ability to inline a variable for the sudo command

i also tried this as suggested here

JavaScript

but with no luck, am i missing something?

Advertisement

Answer

The problem with the first command is that http variable expansion happens before it is set.

JavaScript

Try instead

JavaScript

The syntax is described in man env

JavaScript

Otherwise if the goal is not to affect current shell environment the export and sudo command can be done in a subshell:

JavaScript
Advertisement