1. 程式人生 > >sh: 1: source: not found on ubuntu

sh: 1: source: not found on ubuntu

bash、dash(/bin/bash和/bin/sh)介紹:
Linux中的shell有多種型別,其中最常用的幾種是Bourne shell(sh)、C shell(csh)和Korn shell(ksh)。三種shell各有優缺點。Bourne shell是UNIX最初使用的shell,並且在每種UNIX上都可以使用。Bourne shell在shell程式設計方面相當優秀,但在處理與使用者的互動方面做得不如其他幾種shell。Linux作業系統預設的shell是Bourne Again shell,它是Bourne shell的擴充套件,簡稱Bash,與Bourne shell完全向後相容,並且在Bourne shell的基礎上增加、增強了很多特性。Bash放在/bin/bash中,它有許多特色,可以提供如命令補全、命令編輯和命令歷史表等功能,它還包含了很多C shell和Korn shell中的優點,有靈活和強大的程式設計介面,同時又有很友好的使用者介面。

GNU/Linux 作業系統中的 /bin/sh 是 bash(Bourne-Again Shell)的符號連結,但鑑於 bash 過於複雜,有人把 ash 從 NetBSD 移植到 Linux 並更名為 dash(Debian Almquist Shell),並建議將 /bin/sh 指向它,以獲得更快的指令碼執行速度。Ubuntu 號稱自從他們在 6.10 版裡這樣做了以後,系統啟動速度有了明顯的提升。Debian 計劃在下一個發行版(代號 lenny)中也將 dash 作為預設的 /bin/sh

問題:
最近在搞flask專案時,將所有環境密碼都寫入環境變數,本地執行OK,但是放到Ubuntu機器上,發現讀不出環境變數,但是echo $NAME 正常。

原因說明:
1、Ubuntu系統中,預設使用的shell是/bin/dash,它不支援source命令;
2、由於大多數shell都是使用的/bin/bash,因此簡單粗暴,直接改變shell執行環境

解決方案:
$ls -l which sh
/bin/sh -> dash

$sudo dpkg-reconfigure dash #選擇No
[...]

$ls -l `which sh`
/bin/sh -> bash