码迷,mamicode.com
首页 > 系统相关 > 详细

Ubuntu中执行bash脚本出现"Global symbol "$xxx" requires explicit package name at (eval 1) line 1."

时间:2020-06-24 13:58:30      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:ack   route   简单   target   class   一个   ict   event   nbsp   

问题描述

在Ubuntu14里编写了一个很简单的文件批量重命名脚本

#!/bin/bash
read -p "请输入50递增的起始数字:" startA
echo "\n"
read -p "请输入1递增的起始数字:" startB
echo "\n"
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) line 1."

标签:ack   route   简单   target   class   一个   ict   event   nbsp   

原文地址:https://www.cnblogs.com/qjfoidnh/p/13186971.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!