
我需要在 FreeBSD 監獄中設定一個系統範圍的環境變數(即 NODE_ENV=Production)。
我確實嘗試在 /etc/profile 中設定它,但是當我獲取它時
root@www:/ # source /etc/profile
我有
export: Command not found.
它在主機系統上運行。
我也嘗試將其設為/.chsrc。但這只會使 root 使用者可以使用該變量,而監獄的任何其他使用者則無法使用該變數。
答案1
問:“在 FreeBSD 監獄中設定係統範圍的環境變數。”
/etc/profile
A: 在和中設定變數/etc/csh.cshrc
。
細節
引用自3.9.貝殼
如何設定環境變數在 shell 之間有所不同。在 tcsh(1) 和 csh(1) 中,使用 setenv 設定環境變數。在sh(1)和bash中,使用export來設定目前環境變數。
以下所有例子均在監獄中處決
FreeBSD test_01.example.org 12.0-RELEASE FreeBSD 12.0-RELEASE r341666 GENERIC i386
具有預設 shell 的使用者sh
和bash
/etc/profile
是設定全域環境的正確位置。例如
$ cat /etc/profile
NODE_ENV=production; export NODE_ENV
引用自簡介(4)
所有使用 shell sh(1) 作為登入命令的使用者都會將這些檔案中的命令作為其登入序列的一部分執行。
例如,用戶admin
$ grep admin /etc/passwd
admin:*:1001:1001:User &:/home/admin:/bin/sh
執行/etc/profile
“作為其登入序列的一部分”並設定環境
$ echo $NODE_ENV
production
這種環境將在csh
和tcsh
$ csh
admin@test_01:~ % echo $NODE_ENV
production
也將被保存下來su
$ su
root@test_01:/home/admin # echo $NODE_ENV
production
和中沒有export
命令。這解釋了錯誤csh
tcsh
$ csh
admin@test_01:~ % source /etc/profile
NODE_ENV=production: Command not found.
export: Command not found.
具有預設 shell 的使用者csh
和tcsh
/etc/csh.cshrc
csh
是為和設定全域環境的正確位置tcsh
。例如
root@test_01:~ # cat /etc/csh.cshrc
setenv NODE_ENV production
預設的shellroot
是預設的csh
root@test_01:~ # grep root /etc/passwd
root:*:0:0:Charlie &:/root:/bin/csh
這樣就設定了環境
root@test_01:~ # echo $NODE_ENV
production