To open the environment variables in the string?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
2 views
As in Java to convert a string type

"Tralala ~/bin;${JAVA_HOME} trululu"

in

"Tralala /home/lenochka/bin;/bin/java trululu"

— i.e. expand all the environment variables and a tilde, which is inside the string.


Googled — needed library is not found :(
by | 2 views

4 Answers

0 like 0 dislike
The task is divided into 3 parts
\r
1) the allocation of variable names
2) receive their values
3) Assembly line
\r
For 1, you can use regular expressions, or any template-engine (expensive).
2 you can use the System.getenv
3 — again using regular expressions or simple replacement with a String.replace
by
0 like 0 dislike
You can use System.getProperty(String Property);
Only need for all variables to do a mapping of the parameter of the function. For example:
'JAVA_HOME': 'java.home',
'~': 'user.home'
\r
Java just started learning, so I don't know, maybe there is a more correct version
by
0 like 0 dislike
try to do System.exec("$JAVA_HOME").getOutputStream() and string count. Get what the variable contains
by
0 like 0 dislike
Map env = System.getenv(); for (String envName : env.keySet()) { System.out.format("%s=%s%n", envName, env.get(envName)); }

->
JAVA_HOME=/usr/lib/jvm/java-8-oracle XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/usr/share/upstart/xdg:/etc/xdg XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0 GNOME_KEYRING_CONTROL= LANG=en_us.UTF-8 XDG_SESSION_TYPE=x11 XDG_SESSION_ID=c1 DISPLAY=:0 GDM_LANG=en_us XDG_GREETER_DATA_DIR=/var/lib/lightdm-data/quadra UPSTART_EVENTS=started xsession SESSION=ubuntu DESKTOP_SESSION=ubuntu GPG_AGENT_INFO=/run/user/1000/keyring/gpg:0:1 ...
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
27,842 users