{"id":313,"date":"2020-04-06T21:48:58","date_gmt":"2020-04-06T19:48:58","guid":{"rendered":"http:\/\/xpam.pl\/blog\/?p=313"},"modified":"2024-04-03T01:49:14","modified_gmt":"2024-04-02T23:49:14","slug":"setting-env-variables-with-hyphen-and-running-a-program","status":"publish","type":"post","link":"https:\/\/xpam.pl\/blog\/?p=313","title":{"rendered":"Setting env variables with hyphen and running a program"},"content":{"rendered":"<p>Docker compose allows you very unrestrictive naming of your environment variables. It allows you to use hyphen and other \"special\" characters in variables names. When you need to use these variables in regular shell you are out of luck, bash and many other shells do not allow hyphens in variable names. But this is merely a shell restriction, so how to do it?<\/p>\n<p>With env<\/p>\n<pre><code class=\"language-bash\">env -i &#039;TZ=Europe\/Berlin&#039; \\\n&#039;PORT=8080&#039; \\\n&#039;BASE-URL=http:\/\/localhost:8080&#039; \\\n&#039;DB[0]_CONNECTION-URL=jdbc:postgresql:\/\/localhost:5432\/postgres&#039; \\\n&#039;DB[0]_USERNAME=username&#039; \\\n&#039;DB[0]_PASSWORD=password&#039; java -jar myapp.jar<\/code><\/pre>\n<p>Note that env ignores all inherited env variables so you might need to redefine them:<\/p>\n<pre><code class=\"language-bash\">env -i JAVA_HOME=$JAVA_HOME \\\n&#039;TZ=Europe\/Berlin&#039; \\ \n&#039;PORT=8080&#039; java -jar myapp.jar<\/code><\/pre>\n<p>&nbsp;<\/p>\n<div class=\"wp-post-signature\">\r\n<br \/>\r\n<br \/>\r\n<img src='https:\/\/xpam.pl\/aaaaff.png' title='Moonie' \/> Cen<br \/>\r\n<a href='https:\/\/github.com\/cen1'>GitHub<\/a><br \/>\r\n<a href='https:\/\/eurobattle.net'>Eurobattle.net<\/a><br \/>\r\n<a href='https:\/\/lagabuse.com'>Lagabuse.com<\/a><br \/>\r\n<a href='https:\/\/bnetdocs.org'>Bnetdocs<\/a><br \/>\r\n<\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>Docker compose allows you very unrestrictive naming of your environment variables. It allows you to use hyphen and other \"special\" characters in variables names. When you need to use these variables in regular shell you are out of luck, bash and many other shells do not allow hyphens in variable names. But this is merely [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,3,18],"tags":[],"class_list":["post-313","post","type-post","status-publish","format-standard","hentry","category-linux","category-programming","category-script-magic"],"_links":{"self":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=313"}],"version-history":[{"count":4,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/313\/revisions"}],"predecessor-version":[{"id":565,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=\/wp\/v2\/posts\/313\/revisions\/565"}],"wp:attachment":[{"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xpam.pl\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}