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