Method: Unix::Exec#delete_env_var

Defined in:
lib/beaker/host/unix/exec.rb

#delete_env_var(key, val) ⇒ Object

Delete the provided key/val from the current ssh environment

Examples:

host.delete_env_var('PATH', '/usr/bin:PATH')

Parameters:

  • key (String)

    The key to delete the value from

  • val (String)

    The value to delete for the key



238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/beaker/host/unix/exec.rb', line 238

def delete_env_var key, val
  key = key.to_s
  env_file = self[:ssh_env_file]
  val = Regexp.escape(val).gsub('/', '\/').gsub(';', '\;')
  # if the key only has that single value remove the entire line
  exec(Beaker::SedCommand.new(self['platform'], "/#{key}=#{val}$/d", env_file))
  # value in middle of list
  exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=\\(.*\\)[;:]#{val}/#{key}=\\1/", env_file))
  # value in start of list
  exec(Beaker::SedCommand.new(self['platform'], "s/#{key}=#{val}[;:]/#{key}=/", env_file))
  # update the profile.d to current state
  # match it to the contents of ssh_env_file
  mirror_env_to_profile_d(env_file)
end