简体   繁体   English

在for循环中运行以在Shell脚本中重命名多个文件时出现错误

[英]Error While running for loop for renaming multiple file in shell script

While renaming multiple file in AIX using for loop I am getting error 在使用for循环在AIX中重命名多个文件时,出现错误

${fn/$eisinno/$efilename}": 0403-011 The specified substitution is not valid for this command. $ {fn / $ eisinno / $ efilename}“:0403-011指定的替换对此命令无效。

Input File: 输入文件:

raj_10576_INE728J01019_arya1.pdf

ram_10576_INE728J01019_arya1.pdf

rhaul_10576_INE728J01019_arya1.pdf

sanjay_10576_INE728J01019_arya1.pdf

dinesh_10576_INE728J01019_arya1.pdf

Desired Output File: 所需的输出文件:

raj_10576_Remote_sag.pdf

ram_10576_Remote_sag.pdf

rhaul_10576_Remote_sag.pdf

sanjay_10576_Remote_sag.pdf

dinesh_10576_Remote_sag.pdf

My script is as follow: 我的脚本如下:

#!/bin/bash

eisinno="INE728J01019_arya1.pdf"

evenno=10576

efilename="remote_sag.pdf"


cd /home/rishabh/$eveno

for file in *_$eveno_*.pdf

do
    mv -i "${file}" "${file/$eveno_$eisinno/$eveno_remote_$efilename}"

done

Kindly help me 请帮助我

Use double n in the evenno s and use braces to make sure where a variable ends: evenno使用double n并使用花括号来确保变量在何处结束:

#!/bin/bash
eisinno="INE728J01019_arya1.pdf"
evenno=10576
efilename="remote_sag.pdf"

cd /home/rishabh/${evenno}
for file in *_${evenno}_*.pdf; do
   echo "Debug: ${file} ==> ${file/${evenno}_${eisinno}/${evenno}_remote_${efilename}}"
   # Alternative: 
   echo ${file} | sed "s/${evenno}_${eisinno}/${evenno}_remote_${efilename}/"

   mv -i "${file}" "${file/${evenno}_${eisinno}/${evenno}_remote_${efilename}}"
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM