在 Ubuntu 寫 shell script 也不容易
早期用 Mandriva 時寫了一大堆的 bash shell script,上年嘗試在 Ubuntu 用時,已經發覺不甚妥,有些功能在 Debian 或 Ubuntu 的 bash 是用不了的,例如雙方括號 [[ …… ]]、進行 regular expression match 等等;那類功能沒了不會死人,改一下之後很多 script 都沒事。但自從用了 Ubuntu Feisty 之後,所有 script 都完了。最起碼,array 完全不能用,沒有了這個功能,對我來說就等於不用再寫 script。我想大概 Debian 和 Ubuntu 的人想將 bash 打斷手腳,令其變成完全 posix compliant 的殘廢 shell。
沒法子,現在任何 shell 都信不過了,最信得過的卻又是先天性腦萎縮,唯有在 Perl, Python, PHP 之間選一個。暫時最熟手的是 PHP,雖然如果聽到用 PHP 寫 CLI 的 script 很多人都會瞪大眼,以為我是傻的,但總之要先做到日常的工作,別的待日後才說吧。
大家都是 Linux,預設都是 bash,但 bash script 卻不兼容……即使我本身不打算考慮 portability(反正只是自己用的 script),所用的平台也要逼我考慮,有點諷刺。
The inconsistence system design between distributions always caused by commercial competitive is the most troublesome. They will change GUI a bit and rush to the latest kernel, application. I never think this will happen as it does not exist any motive.
May be the changes are started by Mandrake and Red Hat from the vary early date.
One side opts for the most feature and newest version of everything; another side obeys “the minimum is the best, don’t upgrade if it ain’t break” rule. All of the major distributions are going to these 2 extremes. This is what makes me unable to cope with.
Ubuntu 7.04 的 sh 預設是 dash, 不是 bash
我知道,既然說明了是 bash script,即是說全部以
#!/bin/bash開始的了。不過我的確忘了 Debian 和衍生的 distro 多用 dash 做 default。不過我用最近期的Debian,default shell還是bash喎……
To Karl:
Matthew 指的是, /bin/sh 這個鏈結現在是指到 dash 的。
每個人登入所用的 shell 還是 bash。
bash 3.0+ 有很多”新功能”呢。
我記得還在玩 Mandriva 的時候,當 bash 3.0 剛剛出時,幫 bash 打包的人「媽媽」聲不絕……
如果真的要portability,便應該寫Bourne shell script,不是bash script。bash script本來就不是portable的。
我所指的 portable, 是指同一個程式在不同 Linux 系統,功能也不相同。可以想像一下,假設在一個 Linux 系統寫個 Perl script,然後將那個 script 搬到另一個 distribution 再執行一次,發覺第二個系統的 Perl 因為 compile 時沒有任何 optional feature 而令 script run 不到那種沮喪。
用 dash boot 機快好多……
我剛也被dash耍了……
這幾天在弄Freescale的開發版,裝了部Ubuntu 7.11,想先試試他們提供的那個用ltib (Linux Target Image Builder)砌成的BSP。
可是問題多多,有幾個重要的step無法執行,最後trace了代碼,明明PATH的設定正確,就是無辦法經shell script執行某個perl script,最後直接換回bash就大功告成。
唉……