Ok I can already hear the angry BSD crowd, but csh is not what I called a "sane" shell ? (most of all because it's non-standard, see ...)Yeah, I originally tried adding a file under /etc/profile.d, but that did not work. Since we mostly use csh, it looks as if csh does not read /etc/profile, so I had to add the variable to /etc/csh.cshrc... but that is not the ideal solution.
You should use ~/.login_conf.Hello,
I am in need of setting several "system wide" environment variables. I tried to put them in /etc/csh.cshrc, but that did not work, because each created user can have a different shell. Is there a "best practice" on how to support this across all shells?
Thanks,
{beastie} @ FreeBaSeD-T430 > /home/beastie
→ cat .login_conf
# $FreeBSD$
#
# see login.conf(5)
#
#me:\
# :charset=iso-8859-1:\
# :lang=de_DE.ISO8859-1:
me:\
:charset=UTF-8:\
:lang=en_US.UTF-8:\
:path=/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin /home/beastie/bin /home/beastie/.local/bin /home/beastie/.local/bin:\
:setenv=PAGER=most,\
BROWSER=firefox,\
EDITOR=nano,\
LC_NUMERIC=en_US.UTF-8,\
LC_MONETARY=en_US.UTF-8,\
COLORTERM=truecolor,\
CHEATCOLORS=true:
Ok I can already hear the angry BSD crowd, but csh is not what I called a "sane" shell ? (most of all because it's non-standard, see ...)
If there weren't very powerful, yet conforming, shells (like e.g.Mine differs; sh for scripts, csh interactively.
zsh
), this would make objective sense. But as there are conforming alternatives, is's indeed just a matter of personal taste, which probably grew from habit and/or "BSD tradition" POSIX and other standards is what helps a lot with interoperability. Of course you'll always want to use stuff that's not specified by POSIX. I just prefer stuff that extends POSIX, instead of doing something completely different ?POSIX is useful, but it's not the Holy Grail.
Yeah, I know that ~/.login_conf isn't system-wide. But unlike /etc/login.conf, the configuration in ~/.login_conf survives at least one Display Manager (XDM). I use both and works.BobSlacker ~/.login_conf certainly isn't system-wide configuration, that's what /etc/login.conf is for. But as already mentioned, the problem with that is that there are ways to start a session without using any tool that would read/apply this database, for example login using some X display manager.
Now that's interesting, I wonder how that worksBut unlike /etc/login.conf, the configuration in ~/.login_conf survives at least one Display Manager (XDM). I use both and works.
If there weren't very powerful, yet conforming, shells (like e.g.zsh
), this would make objective sense. But as there are conforming alternatives, is's indeed just a matter of personal taste, which probably grew from habit and/or "BSD tradition"![]()
The price you pay is having to remember two different shell languages and deal with a few other incompatibilities.
% sh -c 'grep -r something / 2>/dev/null'
I don't even criticize that, just pointing it out, because csh ignoring /etc/profile is one of them.
POSIX and other standards is what helps a lot with interoperability. Of course you'll always want to use stuff that's not specified by POSIX. I just prefer stuff that extends POSIX, instead of doing something completely different ?![]()
You're aware this is completely non-standard, right? Given the rest of your post, you might indeed try for exampleSure, just as sh ignores /etc/csh.cshrc and
~/.cshrc <&^}=
zsh
for interactive usage, maybe you actually like it? ?i didn't know that csh is not sane/standard(i tried to use it but its doesn't support VAR=value command, syntax and that really set me off), then why is it in base? mksh is just awesome and bare sh for base, i use it for both root and regular userOk I can already hear the angry BSD crowd, but csh is not what I called a "sane" shell ? (most of all because it's non-standard, see ...)
Well, if you can't rely on a POSIX shell and also can't rely on /etc/login.conf (e.g. because people use display managers to login or whatever), I guess you'll have no other choice than configuring your variable in multiple files. Yes, that suck
"sane" is to some extent subjective, but csh certainly is "non-standard". The thing is, it's traditionally included with any BSD system. The standard for POSIX systems though is "bourne" shells. And there are shells with lots of features likei didn't know that csh is not sane/standard(i tried to use it but its doesn't support VAR=value command, syntax and that really set me off), then why is it in base? mksh is just awesome and bare sh for base, i use it for both root and regular user
zsh
(or GNU's bash
) which conform to POSIX...I like to use oksh when I'm on OpenBSD, everywhere else I use zsh.mksh is just awesome and bare sh for base
tcsh
as delivered with FreeBSD. But: The flaws in the language design persist. And that's the reason why nowadays everyone agrees you really shouldn't ever use a C-shell for scripting.Thank you for links and reply, i know that all necessary/base scripts start with #!/bin/sh(correct me if i am wrong) then why by default we have csh by default on root account, i am not questioning philosophy about shells, i just want to know the reason for csh existing within freebsd base, is it pure traditional or other technical reasons for it?To elaborate a bit on the "C-shell issue", here's a VERY old rant:
Csh Programming Considered Harmful
harmful.cat-v.org
Please, before killing me, consider its age. All the bugs mentioned there probably don't apply totcsh
as delivered with FreeBSD. But: The flaws in the language design persist. And that's the reason why nowadays everyone agrees you really shouldn't ever use a C-shell for scripting.
I just ask: Then why learn different shell languages at all, given there are very comfortable POSIX-compliant shells available? But here, we're back in the realms of "personal taste" ?
You're not wrong. /bin/sh is the minimal standards-compliant (POSIX/bourne) shell in base, that's what should be used for any scripting. And using a minimal shell for that makes sense as well, it reduces the risk to write non-portable scripts.* That said, FreeBSD's /bin/sh got a few features for interactive use (like a useful command history), but it's still kind of minimal.i know that all necessary/base scripts start with #!/bin/sh(correct me if i am wrong)
You certainly want a more comfortable shell for interactive use with features added beyond what POSIX specifies.then why by default we have csh by default on root account, i am not questioning philosophy about shells, i just want to know the reason for csh existing within freebsd base, is it pure traditional or other technical reasons for it?
bash
, which is POSIX-compliant, but offers tons of extensions, and many distributions install it as /bin/sh – the result is lots of "bashisms" in shell scripts written by people who only know Linux systems