ExportManager { public String addVariable(String line) { Matcher variableMatcher = exportPattern.matcher(line); if (variableMatcher.matches()) { String name = variableMatcher.group(2); String value = variableMatcher.group(3); if (value.contains(String.valueOf(DOLLAR + name))) { value = value.replace(String.valueOf(DOLLAR + name), variables.get(name)); } variables.put(name, value); if(listener != null) listener.exportChange(name, value); return null; } return "export: usage: export [name[=value] ...]"; } ExportManager(File exportFile);  ExportManager(File exportFile, ExportChangeListener listener);  ExportManager(File exportFile, boolean exportUsesSystemEnvironment);  ExportManager(File exportFile, boolean exportUsesSystemEnvironment, ExportChangeListener listener); Set<String> keys(); String addVariable(String line); String getValue(String key); String getValueIgnoreCase(String name); String listAllVariables(); void persistVariables(); List<String> getAllNamesWithEquals(); List<String> getAllNames(); List<String> findAllMatchingKeys(String word);  }
@Test public void testAddVariable() throws IOException { ExportManager exportManager = new ExportManager(new File(Config.getTmpDir()+Config.getPathSeparator()+"aesh_variable_test")); exportManager.addVariable("export TEST=/foo/bar"); assertEquals("/foo/bar", exportManager.getValue("TEST")); exportManager.addVariable("export FOO=/opt"); exportManager.addVariable("export FOO2=$FOO"); assertEquals("/opt", exportManager.getValue("$FOO")); assertEquals("/opt", exportManager.getValue("${FOO}")); assertEquals("/opt", exportManager.getValue("FOO2")); assertEquals("/opt", exportManager.getValue("${FOO2}")); assertEquals("/opt:/foo/bar", exportManager.getValue("$FOO:$TEST")); assertEquals("/opt:/foo/bar", exportManager.getValue("$FOO2:${TEST}")); assertEquals("/opt:/foo/bar:/foo", exportManager.getValue("$FOO2:$TEST:/foo")); assertEquals("", exportManager.getValue("$FOO3")); exportManager.addVariable("export PATH=$FOO2:$TEST:/foo"); exportManager.addVariable("export PATH=$PATH:/bar"); assertEquals("/opt:/foo/bar:/foo:/bar", exportManager.getValue("$PATH")); exportManager.addVariable("export FOO2=/bin"); assertEquals("/bin", exportManager.getValue("${FOO2}")); assertEquals("/bin:/foo/bar:/foo:/bar", exportManager.getValue("$PATH")); exportManager.addVariable("export TEST=/bla /ha"); assertEquals("/bla", exportManager.getValue("TEST")); assertEquals("ls -la /bla", exportManager.getValue("ls -la $TEST")); assertEquals("/bla ls -la /bla", exportManager.getValue("$TEST ls -la $TEST")); }