Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement printenv #5

Merged
merged 10 commits into from
Jul 7, 2021
Merged

Implement printenv #5

merged 10 commits into from
Jul 7, 2021

Conversation

ShenTengTu
Copy link
Contributor

Prepare for printenv implementation.

Currently, I implement a simple function of printing available parameters, which can be used as a template reference for developing other utilities in the future.

@ShenTengTu ShenTengTu mentioned this pull request Jul 6, 2021
@ShenTengTu
Copy link
Contributor Author

ShenTengTu commented Jul 6, 2021

The feature (environment variable printing) is basically completed.

The order of os.environ() is different from the original printenv(run on Ubuntu 18.04, coreutils 8.28).

See comment-875244187.

@ShenTengTu
Copy link
Contributor Author

ShenTengTu commented Jul 6, 2021

I am writting a testing script, I get different output from os.execute.

In terminal, printenv --null LANGUAGE LANG output like following (run on Ubuntu 18.04, coreutils 8.28):

zh_TW:zhzh_TW.UTF-8

Use os.execute to execute the command (run on V 0.2.2 6dde9f7):

result_origin := os.execute('printenv --null LANGUAGE LANG')
println(result_origin.output)

the output is not zh_TW:zhzh_TW.UTF-8, but zh_TW:zh

@JalonSolov
Copy link
Contributor

Since it is important that the output is as correct as possible (even if it's in a different order), I'd prefer to hold this until the the V issue is fixed. Any objections?

@ShenTengTu
Copy link
Contributor Author

Since it is important that the output is as correct as possible (even if it's in a different order), I'd prefer to hold this until the the V issue is fixed. Any objections?

I will commit the initial version of the test script and add comments about the issues to the code, then wait for the issues to be resolved.

@ShenTengTu
Copy link
Contributor Author

ShenTengTu commented Jul 7, 2021

The order of os.environ() is different from the original printenv(run on Ubuntu 18.04, coreutils 8.28).

original printenv output is like:

CLUTTER_IM_MODULE=...
FNM_LOGLEVEL=...
LS_COLORS=...
DENO_INSTALL=...
FNM_ARCH=...
...

In current V implementation, I use os.environ() to fetch all env :

for k, v in os.environ() {
	mut s := '$k=$v'
	if nul_terminate {
		print(s)
	} else {
		println(s)
	}
}

The output is like:

PYENV_VIRTUALENV_INIT=...
LESSOPEN=...
USER=...
MPY_PATH=...
LANGUAGE=...
...

The original output has a specific order, not just in alphabetical order.

@spytheman
Copy link
Member

The problem occurs if you do v run file.v, because in this case V itself manipulates the environment (it sets VEXE and VTMP for example).

If you instead first compile your program, and then run it, it will produce the same as printenv:
image

@spytheman spytheman closed this Jul 7, 2021
@spytheman spytheman reopened this Jul 7, 2021
@spytheman spytheman merged commit 399e11b into vlang:main Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants