Ubuntu中执行bash脚本出现"Global symbol "$xxx" requires explicit package name at (eval 1) lin
Posted qjfoidnh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu中执行bash脚本出现"Global symbol "$xxx" requires explicit package name at (eval 1) lin相关的知识,希望对你有一定的参考价值。
问题描述
在Ubuntu14里编写了一个很简单的文件批量重命名脚本
#!/bin/bash read -p "请输入50递增的起始数字:" startA echo " " read -p "请输入1递增的起始数字:" startB echo " " read -p "请输入1递增的结束数字:" endB while [ $startB -le $endB ] do rename ‘s/traceroute-1000-$startA/traceroute-1000-$startB/‘ * let startA+=50 let startB+=1 done
但运行后却报了之前从没见过的错误:
Global symbol "$startA" requires explicit package name at (eval 1) line 1.
Global symbol "$startB" requires explicit package name at (eval 1) line 1.
在查询后,发现大多数答案提到此错误都是在Perl脚本里;而且此后经过一些修改,还出现过
Bareword "Build" not allowed while "strict subs" in use at (eval 1) line 1.
这样的报错信息。
解决方案
在某国外论坛上找到了原因
It‘s a Perl error.
(In Ubuntu) the rename command is a Perl script and in the terminal emulator you are using Bash. The single quotes you used in your command are preventing Bash to perform the parameter expansion. Please see: http://mywiki.wooledge.org/Quotes
总的来说,rename的实现是一个Perl脚本,而Perl的语法与Bash有些不同,将rename句改为如下即可
rename "s/traceroute-1500-${startA}/traceroute-1500-${startB}/" *
It‘s a Perl error.
(In Ubuntu) the rename command is a Perl script and in the terminal emulator you are using Bash. The single quotes you used in your command are preventing Bash to perform the parameter expansion. Please see: http://mywiki.wooledge.org/Quotes
以上是关于Ubuntu中执行bash脚本出现"Global symbol "$xxx" requires explicit package name at (eval 1) lin的主要内容,如果未能解决你的问题,请参考以下文章
从 bash 脚本检测“Windows 上的 Ubuntu”与本机 Ubuntu [重复]
shell脚本执行时报"bad interpreter: Text file busy"的解决方法