Timeline for posix shell: print list of environment variable names (without values)
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 22, 2019 at 21:55 | comment | added | todd_dsm |
@juan okay, you're looking for the functionality of an associative array. That's not available in ash/dash/sh. You should definitely be using something like bash. If not, those work-arounds will start getting super frustrating; good luck.
|
|
| Nov 16, 2019 at 18:12 | comment | added | Juan |
@todd_dsm: here's an example of the failure with multiline env vars: env ML=$'abc=123:\n def=456' sh -c 'printf "${ML}\n"; echo ; printf "$ML" | sed "s;=.*;;"; echo'
|
|
| Nov 16, 2019 at 18:11 | comment | added | Juan | @todd_dsm: re: why posix? For portability generally. I want my scripts to work with any shell, notably any /bin/sh whether that underlying shell is bash, dash, ksh, "standard" bourne shell. More simply put, bash is not available on many systems that my scripts must run on. | |
| Nov 5, 2019 at 0:45 | comment | added | todd_dsm |
Using dash in debian, I get the same results with the command above or, the modified printenv | sed 's;*=.;;' | sort to get the values. I exported the variable yo and assigned it your first comment above; it printed as expected, with multiple lines. not sure what you're experiencing but there shouldn't be truncated output. run the command in the shell; whatever it outputs there is how it should work; expect no truncating. Then, within the context of TERMCAP/screen/iirc; should be the same. If the output does not match then it's likely an issue with one of those programs.
|
|
| Nov 5, 2019 at 0:24 | comment | added | todd_dsm | just curious, why restrict yourself to the bourne (posix) shell? being posix-compliant is great but you lose a great deal of functionality in that pursuit. you can be portable and NOT posix-compliant with bash; it's part of the GNU family. | |
| Nov 3, 2019 at 19:21 | comment | added | Juan |
The tidbit you edited out in your original post was interesting for bash: compgen -e. It doesn't help for my portable scripting (e.g., when bash is not available), but it's interesting.
|
|
| Nov 3, 2019 at 17:46 | comment | added | Juan | @todd_dsm - This fails for environment variables that have values that span more than one line (e.g., sometimes TERMCAP - I see this when in a screen(1) session, IIRC). So this answer does not meet the requirements described in the original question. I also like simple, but this does not work generally. | |
| Sep 26, 2019 at 17:35 | comment | added | Chris Davies |
export AAA=$'multi\nBBB=line'
|
|
| Sep 26, 2019 at 17:32 | history | edited | todd_dsm | CC BY-SA 4.0 |
added 22 characters in body
|
| Sep 26, 2019 at 17:24 | history | edited | todd_dsm | CC BY-SA 4.0 |
answered the question more specific to POSIX
|
| Sep 25, 2019 at 17:30 | history | answered | todd_dsm | CC BY-SA 4.0 |