简体   繁体   English

函数内部sed命令中的bash语法错误,在命令行上运行正常

[英]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.

相关问题 bash脚本中的sed工作不正常:但它可以在命令行上运行 - Sed inside bash script not working: But it works on command line SED命令在命令行中有效,但在脚本中无效[找不到文件错误] - SED command works in command line but not inside script [file not found error] 用于Nagios错误的Bash脚本:在stdout上没有输出-在命令行上工作正常 - Bash script for nagios error: No output on stdout - works fine on command line 使用sed设置变量可在命令行上运行,但不能使用bash脚本 - using sed to set a variable works on command line, but not bash script 通过Shell脚本执行命令时出现Awk语法错误,但是从Linux bash shell执行命令时,该命令运行正常 - Awk syntax error when command is executed through a shell script however the command works fine when executed from Linux bash shell 通过命令行使用Git是有问题的,但是bash可以正常工作吗? - Using Git via command line is buggy, but bash works fine? Debian bash脚本在命令行中运行良好; 在crontab中失败 - Debian bash script works fine from command line; fails in crontab python中的Bash命令抛出语法错误 - Bash command inside python throwing syntax error sed替换在命令行上有效,但在sed脚本中无效;( - sed substitution works on command line but not in sed script ;( 在bash函数中访问命令行参数? - Access command line argument inside bash function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM