4 ms·
I'm not really well-versed in what happens when you replace a shell and then run your programs with it, but can someone ELI5 how does this get away with making
by gear54rus 10y ago
I'm not really well-versed in what happens when you replace a shell and then run your programs with it, but can someone ELI5 how does this get away with making 'env variables typed'.
How is the program like 'ls' going to see a variable that is an array when originally it was a string delimited with ':'?
- roblabla 10y agoIt will see a string delimited with ':'. The point is that while inside xonsh, your variable is typed, and then xonsh hands the env in the expected way to the subprocesses.
- gear54rus 10y agoSo basically it goes back to string from array by simply unconditionally joining it on a ':'? I guess that makes some sense... But isn't this convention (delimited by ':') only for PATH?
- roblabla 10y agoMost path arrays are :-concatenated on unixes (RPATH, LD_PRELOAD, etc...), so the convention holds for the majority case. There might be a way to specify the serialization of your array somewhere, but I can't find it in the doc.
- klibertp 10y agohttps://docs.python.org/2/library/os.html#os.pathsep https://docs.python.org/2/library/os.html#os.pathsep
- rkangel 10y agoThe convention holds for other lists too (usually lists of directories). The important thing is that there is a similar but different convention on Windows (';' is used), and xonsh abstracts that away in the same way Python does.
- BlanketLogic 10y ago> How is the program like 'ls' going to see a variable that is an array when originally it was a string delimited with ':'? There are two things here: the command 'ls' that you type on your shell and the executable named 'ls' located in "/bin/ls" (or wherever) which can list directories. Most shells, when encounter a command X (say, 'ls') they see their 'context' to see if 'X' is defined. If yes, they will execute it. If not, they will assume that the X is an executable and try to execute it. That's what happening here. Perhaps the following silly script helps? #!/bin/ls ls () { echo "MYLS $*" } ls $* HTH
- gear54rus 10y agoYes, that I get. I was asking how is the translation from shell to inside of a program happen. On linux, I presume it's done via getenv(3), which means that it can only support strings. The post below says that it simply joins on a ':'. Is that safe for all or even most cases (except obviously PATH, which is delimited by ':')?