gpt4 book ai didi

linux - 如何解析输出并将其存储到变量中

转载 作者:太空宇宙 更新时间:2023-11-04 09:37:00 25 4
gpt4 key购买 nike

如何从以下命令中获取值 8.4.1 并使用 shell 脚本将其存储到变量中。

   [root@testserver bin]# ./psql --version

**psql (PostgreSQL) 8.4.1**

contains support for command-line editing

[root@testserver bin]#

提前致谢。

最佳答案

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

关于linux - 如何解析输出并将其存储到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25622062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com