利用uniread 解決 linux下的sql*plus 命令行歷史回調(diào)功能
作者: fenng
大家知道, 在 windows 平臺 命令行中的 sql*plus 有命令行歷史回調(diào)的功能,在sql*plus工具下面,可以利用鍵盤的
"向上向下"箭頭鍵對命令行的進行回調(diào).而在linux上則沒有該功能(雖然 shell 可以做到這一點,但是 sql*plus 不可以).
而該功能對于cli愛好者來說幾乎是不可缺的,不知道為什么 oracle 不把這個功能加進來.不得而知了.
一些sql*plus 的替代產(chǎn)品(如 gqlplus 以及yasql)具備command-line editing 和command history的功能, 但是這
些產(chǎn)品的開發(fā)進度較慢--有的甚至已經(jīng)停止了更新.
(參見: gqlplus http://sourceforge.net/projects/gqlplus 以及 yasql http://sourceforge.net/projects/yasql/
等 sql*plus 替代工具 ).
在網(wǎng)絡(luò)上閑逛的時候, 發(fā)現(xiàn)了一個在linux下面的解決辦法, 現(xiàn)在和大家共享.
該工具叫做uniread ( http://sourceforge.net/projects/uniread/ ) ,熟悉linux下變成的朋友可能看到這個名字已經(jīng)
想起了一些東西:readline . 不錯,該工具就是利用gnu的readline庫來完成我們的需求的.
我們先看一下對該工具的介紹:
uniread - universal readline - adds full readline support (command editing, history, etc.) to any existing
interactive command-line program. common examples are oracle's sqlplus or jython. uniread will work
on any posix platform with perl.
可以看出,該工具可以對任何既有的交互命令行程序都可提供完備的readline支持.
從該站點下載源程序.目前的穩(wěn)定版本是1.01.
在安裝該工具之前系統(tǒng)必須安裝好perl, 此外還必須要三個工具包:
gnu readline
http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
term::readline::gnu
http://search.cpan.org/dist/term-readline-gnu/
io::tty
http://search.cpan.org/dist/io-tty/
其中g(shù)nu readline 上面的網(wǎng)頁在我的機器上打不開(不可訪問?),如果你也是同樣情況,可以到
http://www.gnu.org/directory/readline.html 這個頁面下載.
下載后,首先解壓縮:
# tar -xzvf readline-4.3.tar.gz
進入進入到該目錄中編譯并安裝:
# ./configure
# make
# make install
后面兩個的安裝: tar -zxvf ....
進入到該目錄中:
# perl makefile.pl
# make
# make install
都安裝完了之后,進行 uniread 的安裝:
#tar -xzvf uniread-1.01.tar.gz
#cd uniread-1.01
#./configure
#make
#make install
注: 以上的命令行操作所在絕對路徑為了方便而省略,你的環(huán)境肯定會和我的不同,此外,建議使用普通用戶編譯,然后用 root 進行
make install .
都安裝完了之后
切換到oracle用戶下:
$ uniread sqlplus /nolog
輸出類似如下:
[uniread] loaded history (12 lines) //我的已經(jīng)運行一次了,uniread 緩沖了12行history
sql*plus: release 10.1.0.2.0 - production on sat mar 6 00:23:05 2004
copyright (c) 1982, 2004, oracle. all rights reserved.
sql>
查看uniread的manual:
$man uniread
你可以做個sqlplus 的別名 ,uniread的使用是透明的,是不是很方便了? 不要忘了:這個工具是有通用性的,不止是 sql*plus
可以這樣用,其他類似的命令行程序也能如此的.
參考內(nèi)容:
uniread的站點 http://sourceforge.net/projects/uniread
gnu readline http://www.gnu.org/directory/readline.html
"the readline library provides a set of functions for use by applications that allow users to edit
command lines as they are typed in."
目前還算萬能的google http://www.google.com
原文出處:
<a >http://www.dbanotes.net/oracle/uniread-howto.htm</a>