LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-05-2019, 06:04 PM   #1
shogun1234
Member
 
Registered: May 2004
Posts: 226

Rep: Reputation: 15
Proper way to setup environment variables


In command line, I understand I can export environment variable by export. For instance,

Code:
$ export JAVA_OPTS="..."
$ java -cp ./ $JAVA_OPTS ...
But sometimes I seems to see some usage such
Code:
env JAVA_OPTS="..."; java -cp ... $JAVA_OPTS
or
Code:
JAVA_OPTS="..."; java -cp ... $JAVA_OPTS
I can't remember the exact way those commands to export environment variables (so I believe the syntax I use could be wrong). Thus I am interested to learn what's a more appropriate way to export environment variables or (if it's just different syntax as unix allows different approach the goal by different ways) the differences between those syntax.

Thanks
 
Old 11-05-2019, 08:20 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
There's lots of information available on-line.
I believe that all three of your examples are "proper," each in their place. The main difference is where the variables live and whether or not they get propagated.

export is a bash built-in: see man export, then search for export. Other shells may have different syntax for exporting a variable.
see man env

What, specifically, are you concerned about?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Proper way to backport File Manager or Desktop Environment in Debian 9? linustalman Linux - Software 3 07-15-2018 10:21 AM
[SOLVED] setup environment variables for groups Jerry Mcguire Linux - Newbie 2 06-16-2010 10:01 PM
proper way to setup notepad++ to execute bash scripts? PiNPOiNT Programming 4 04-25-2009 11:27 AM
Bash: How to setup "global" environment variables? ArthurHuang Programming 2 02-07-2008 12:24 PM
How to setup environment variables?? devraj Linux - Newbie 2 12-17-2001 04:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration