Two shellscripts ......

Source: Internet
Author: User
Article Title: very convenient two shellscripts ....... Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Author: juner
  
Recently, I made the system a new one, so it became a system in which WIN98 and linux coexist. However, after working for a long time, I found it inconvenient (all file names under WIN98 are in uppercase, in linux, the file names are generally lowercase characters ). When using mcopy, the copied file names are in uppercase, which is inconvenient for linux operations!
So I wrote two shell scripts. I used them to facilitate a lot of operations over the past few days. now I want to share them with my friends in dual systems (I know there are a lot of people using dual systems like me! ;-), Someone should be able to use it. The script is very simple, but it is packaged before it is posted (it looks like a system command, huh, huh ). However, you can only change the file name in the current directory (that is, you can only: % upks2lowks * or % upks2lowks myfile, but not % upks2lowks/mydir/myfile, but there will be errors!
The script content is as follows:
  
#! /Bin/sh
  
# This Shell Script can change UPPER-case filename to low-case filename.
  
Error = 0; count = 0
Number = $ (echo * |/usr/bin/wc-w)
  
If ["$1" = "-h"-o "$1" = "-- help"]; then
Echo "Usage: upks2lowks [PATH] [FILENAME]..."
Echo "Description: Change \" FILENAME \ "to \" filename \"! "
Echo ""
Echo "-h, -- help display this info and exit"
Echo "-v, -- version display version info and exit"
Echo ""
Echo "Report bugs ."
Echo "PS: I think U can modify it by nothing! It's just a shell script! ;-)"
Exit
Fi
  
If ["$1" = "-v"-o "$1" = "-- version"]; then
Echo "A tool form my file-utils, no version info! "
Echo "(maybe ver0.0.0 )?! (^ O ^ )"
Echo "Written by Juner. L"
Echo ""
Echo "Copyright (C) Juner"
Echo "This is free software; see the source for copying conditions. There is NO"
Echo "warranty; not even for MERCHANTABILITY or fitness for a participant PURPOSE ."
Exit
Fi
  
If [-z "$1"]; then
/Usr/bin/printf "\"
Echo "Just put the \" FILENAME \ "follow the command! "
Else
For I in $ *
Do
If [-e "$ I"-a-w "$ I"]; then
File = $ (echo $ I |/usr/bin/tr "[A-Z]" "[a-z]")
If ["$ I" = "$ file"]; then
Echo "The file \" $ I \ "is already lowcased! "
Count = $ (/usr/bin/expr 1 + $ count)
Else
Echo "$ I => $ file"
/Bin/mv-f $ I $ file 2>/dev/null
Fi
Else
Echo "warning: file \" $ I \ "not exist OR you have no \" w \ "right to file! "
Fi
Done
If ["$ number"-eq "$ count"]; then
Echo "all file (s) is lowcased! "
Else
Echo "$ count file (s) already lowcased! "
Fi
Fi
  
There is another one that is similar to it. it only changed a few small places and changed the lowercase file name to uppercase, as shown below:
  
#! /Bin/sh
  
# This Shell Script can change low-case filename to UPPER-CASE filename.
  
Error = 0; count = 0
Number = $ (echo * |/usr/bin/wc-w)
  
If ["$1" = "-h"-o "$1" = "-- help"]; then
Echo "Usage: lowks2upks [path] [filename]..."
Echo "Description: Change \" filename \ "to \" FILENAME \"! "
Echo ""
Echo "-h, -- help display this info and exit"
Echo "-v, -- version display version info and exit"
Echo ""
Echo "Report bugs ."
Echo "PS: I think U can modify it by nothing! It's just a shell script! ;-)"
Exit
Fi
  
If ["$1" = "-v"-o "$1" = "-- version"]; then
Echo "A tool form my file-utils, no version info! "
Echo "(maybe ver0.0.0 )?! (^ O ^ )"
Echo "Written by Juner. L"
Echo ""
Echo "Copyright (C) Juner"
Echo "This is free software; see the source for copying conditions. There is NO"
Echo "warranty; not even for MERCHANTABILITY or fitness for a participant PURPOSE ."
Exit
Fi
  
If [-z "$1"]; then
/Usr/bin/printf "\"
Echo "Just put the \" filename \ "follow the command! "
Else
For I in $ *
Do
If [-e "$ I"-a-w "$ I"]; then
File = $ (echo $ I |/usr/bin/tr "[a-z]" "[A-Z]")
If ["$ I" = "$ file"]; then
Echo "the file \" $ I \ "IS ALREADY UPPERCASED! "
Count = $ (/usr/bin/expr 1 + $ count)
Else
Echo "$ I => $ file"
/Bin/mv-f $ I $ file 2>/dev/null
Fi
Else
Echo "WARING: FILE \" $ I \ "NOT EXIST or YOU HAVE NO \" w \ "RIGHT TO FILE! "
Fi
Done
If ["$ number"-eq "$ count"]; then
Echo "all file (S) is uppercased! "
Else
Echo "$ count FILE (S) already uppercased! "
Fi
Fi
  
Continued
  
After learning about gawk, I have optimized the above two scripts. the changed script can change the file name under any Directory (directory/file with write permission,
That is to say, it can be in any Directory
% Upks2lowks/home/juner/tmp /*
Instead of having
% Cd/home/juner/tmp/
% Upks2lowks *
The modified shell script is as follows:
(If the command path is different from that on your machine, change it to the same path)
  
--------------------------------------
#! /Bin/sh
  
# This Shell Script can change UPPER-CASE filename to low-case filename.
  
# Init the vars!
  
Error = 0; count = 0
Number = $ (echo $ * |/usr/bin/wc-w)
  
# End of the "init the vars "!
  
  
# Process the parameter (s )!
  
If ["$1" = "-h"-o "$1" = "-- help"]; then
Echo "Usage: $0 [PATH] [FILENAME]..."
Echo "Description: Change \" FILENAME \ "to \" filename \"! "
Echo ""
Echo "-h, -- help display this info and exit"
Echo "-v, -- version display version info and exit"
Echo ""
Echo "Report bugs ."
Echo "PS: I think U can modify it by nothing! It's just a shell script! ;-)"
Exit 0
Fi
  
If ["$1" = "-v"-o "$1" = "-- version"]; then
Echo "upks2lowks (a tool form my file-utils) ver0.1a"
Echo "Written by Juner. L"
Echo ""
Echo "Copyright (C) Juner"
Echo "This is free software; see the source for copying conditions. There is NO"
Echo "warranty; not even for MERCHANTABILITY or fitness for a participant PURPOSE ."
Exit 0
Fi
  
# End of the "process the parameter (s )"!
  
  
# Working part!
  
If [-z "$1"]; then
/Usr/bin/printf "\"
Echo "Just put the \" FILENAME \ "follow the command! "
Else
For I in $ *
Do
Declare-x filez = $ (echo $ I |/bin/awk BEGIN '{FS = "/"} {print $ NF }')
Pathz = $ (echo $ I |/bin/awk BEGIN '{FS = ENVIRON ["filez"]} {print $1 }')
If [-e "$ I"-a-w "$ I"]; then
File = $ (echo $ filez |/usr/bin/tr "[A-Z]" "[a-z]")
  
# Sorry, when I posted a post, I directly pasted the above and changed "$ I" to "$ filez" to ignore it. I have changed it now (but the one below is correct)
  
If ["$ filez" = "$ file"]; then
Echo "The file \" $ I \ "is already lowcased! "
Count = $ (/usr/bin/expr 1 + $ count)
Else
Echo "$ pathz $ filez => $ pathz $ file"
/Bin/mv-f $ pathz $ filez $ pathz $ file 2>/dev/null
Fi
Else
Echo "warning: file \" $ I \ "not exist OR you have no \" w \ "right to file! "
Fi
Done
If ["$ number"-eq "$ count"]; then
Echo "all file (s) is lowcased! "
Else
Echo "$ count file (s) already lowcased! "
Fi
Fi
  
# End of the "working part "!
--------------------------------------
  
The same is true for another file.
  
--------------------------------------
#! /Bin/sh
  
# This Shell Script can change low-case filename to UPPER-CASE filename.
  
# Init the vars!

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.