我有一個多行 sed 命令,它在我本地運行的腳本中運行良好,但在 Jenkins 構建腳本中給我一個錯誤。
這是命令:
sed \
-i -r -e "s/(project\(.* VERSION\s )[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\s*\)/\1$RELEASE_MAJOR\.$RELEASE_MINOR\.$RELEASE_MICRO \)/" \
-i -r -e "s/(set\(.* APPMANAGER_MAJOR_VERSION\s )[0-9]{1,2}\s*\)/\1$RELEASE_MAJOR \)/" \
-i -r -e "s/(set\(.* APPMANAGER_MINOR_VERSION\s )[0-9]{1,2}\s*\)/\1$RELEASE_MINOR \)/" \
-i -r -e "s/(set\(.* APPMANAGER_MICRO_VERSION\s )[0-9]{1,2}\s*\)/\1$RELEASE_MICRO \)/" \
${CMAKE_FILE}
我不斷收到此錯誤訊息:
sed -i -r -e 's/(project\(.* VERSION\s )[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\s*\)/\114\.0\.0 \)/' -i -r -e 's/(set\(.* APPMANAGER_MAJOR_VERSION\s )[0-9]{1,2}\s*\)/\114 \)/' -i -r -e 's/(set\(.* APPMANAGER_MINOR_VERSION\s )[0-9]{1,2}\s*\)/\10 \)/' -i -r -e 's/(set\(.* APPMANAGER_MICRO_VERSION\s )[0-9]{1,2}\s*\)/\10 \)/' /apps/artefacts/jenkins_workspace/AI/Release/RDK-AI-Branch_OFF/asappsserviced/asappsserviced/appinfrastructure/RDK/AppManager/CMakeLists.txt
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-c, --copy
use copy instead of rename when shuffling files in -i mode
-b, --binary
does nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX (
open files in binary mode (CR LFs are not treated specially))
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help
display this help and exit
--version
output version information and exit
If no -e, --expression, -f, or --file option is given, then the first
non-option argument is taken as the sed script to interpret. All
remaining arguments are names of input files; if no input files are
specified, then the standard input is read.
我的本地 bash 版本是GNU bash,版本 4.4.20(1)-release (x86_64-pc-linux-gnu)和 sed 是版本4.4。
在 Jenkins 上,bash 的版本是GNU bash,版本 4.2.46(2)-release (x86_64-redhat-linux-gnu)和 sed 是版本4.2.2。
變數 CMAKE_FILE 包含指向包含如下文本的檔案的路徑:
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required( VERSION 3.10.0 )
# Project setup
project( MyApp LANGUAGES C CXX VERSION 14.0.0 )
# Set the major and minor version numbers (also used by plugins)
set( APPMANAGER_MAJOR_VERSION 14 )
set( APPMANAGER_MINOR_VERSION 0 )
set( APPMANAGER_MICRO_VERSION 0 )
我正在使用 sed 來更新版本號。
知道如何解決這個問題嗎?
uj5u.com熱心網友回復:
我終于解決了!由于我有一個不支持擴展正則運算式的舊版本 sed,我必須執行以下操作才能使用基本正則運算式 (BRE):
- 轉義組,即左括號
(和右)括號 - 取消轉義文字括號
- 逃避
特殊意義 - 轉義括號,即
{和}
我發現此參考資料很有用,但它沒有提及任何有關組的內容。顯然在 BRE 格式中,組的括號必須轉義,而文字括號則不需要。
所以這對我有用:
sed \
-i -e "s/\(project.*VERSION\)\s\ [0-9]\{1,2\}\.[0-9]\{1,2\}\.[0-9]\{1,2\}\s\ )/\1 $major\.$minor\.$micro\ )/" \
-i -e "s/\(set.*APPMANAGER_MAJOR_VERSION\)\s\ [0-9]\{1,2\}\s*)/\1 $major )/" \
-i -e "s/\(set.*APPMANAGER_MINOR_VERSION\)\s\ [0-9]\{1,2\}\s*)/\1 $minor )/" \
-i -e "s/\(set.*APPMANAGER_MICRO_VERSION\)\s\ [0-9]\{1,2\}\s*)/\1 $micro )/" ${FILE}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/536826.html
標籤:狂欢詹金斯sed逃避
上一篇:從文本正文中提取并列出兩個分隔符匹配之間的字串的每次出現
下一篇:獲取diff并用awk替換字串
