如何从以下命令获取值8.4.1并使用shell脚本将其存储到变量中。
[root@testserver bin]# ./psql --version
**psql (PostgreSQL) 8.4.1**
contains support for command-line editing
[root@testserver bin]#
提前致谢。
答案 0 :(得分:2)
LINE=`psql --version | grep -oE "[0-9\.]+"` && echo $LINE
grep - print lines matching a pattern
-E - using regex
-o - showing only matching result, not a whole line
[0-9\.]+ - regex, which find a string with numbers and dots