[英]bash syntax error in sed command inside function, works fine on command line
I've got aa bash script with two functions, one is the main function which includes a case command, that case command will then call a second function and pass a specific argument. 我有一个带有两个函数的bash脚本,一个是包含case命令的main函数,case命令然后将调用第二个函数并传递一个特定的参数。
In the second function I have a command that works on the command line, but when run as part of the bash script I get the following error: 在第二个函数中,我有一个在命令行上运行的命令,但是当作为bash脚本的一部分运行时,我收到以下错误:
: line 57: syntax error near unexpected token `('
: line 57: ` local DATE=`echo $URL|sed -r 's/.*____([0-9]{1,2})_([0-9]{1,2})_([0-9]{1,2}).*/20\3-\1-\2/;s/-([0-9]{1})-/-0\1-/;s/-([0-9]{1})$/-0\1/'`'
the function is, 功能是,
dlshow ()
{
local URL=$1
echo "URL: "$URL
local DATE=`echo $URL|sed -r 's/.*____([0-9]{1,2})_([0-9]{1,2})_([0-9]{1,2}).*/20\3-\1-\2/;s/-([0-9]{1})-/-0\1-/;s/-([0-9]{1})$/-0\1/'`
I can't figure out why as a bash command I get the error. 我无法弄清楚为什么作为bash命令我得到错误。
尝试这个:
echo $URL | sed -e '...' | { read DATE ; ... ; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.