Linux bulk modification of file suffix shell script

Source: Internet
Author: User

I wrote a shell script to modify the suffix and learned it with everyone.
Below isSource code: The copy storage is myrename. Sh, which can be used in full accordance with the instructions.
Here, I would like to remind beginners that single quotation marks and reverse quotation marks (the one on the left of keyboard 1) are different. For example, FF = 'ls | grep * is used here *. $ 1', which is a quotation mark! When I first started learning, I looked at the print in the book, so I had a hard time and did not know what went wrong ......
#! /Bin/bash

# Format:
#./Myrename. Sh arg1 arg2
# For example, the first parameter of./myrename. Sh cc c is the suffix to be modified, and the second parameter is the parameter name after modification,
# For example, CC is the suffix to be modified, and C is the suffix after modification.

# Instructions:
# Copy this file to a folder with the suffix to be changed
# Enter bash
# Switch to the folder where the shell file is located
# Note: add the execution permission for shell, chmod + x myrename. Sh

Batch_rename ()
{
FF = 'ls | grep *. $1'
For f in $ FF
Do
MV $ f 'basename $ F. $ 1'. $2
Done
FF = 'LS-L | grep ^ d | cut-d ""-F 9 -'
# Echo $ FF
For f in $ FF
Do
CD $ F
# Ls
Batch_rename
CD ..
Done
}

Batch_rename $1 $2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.