Shell handles files that contain spaces in the file name

Source: Internet
Author: User

Recently learning Gradle, using the git clone command to download some information, but the file name contains a space, it does not seem very comfortable, so think of using shell script to batch it, remove the file name of the space, note that this is to remove all the blanks

git clone https://github.com/waylau/gradle-2-user-guide-demos.git

Shell script:

########################################################################## File name:handle.sh# author:liuwei# Mail: [Email protected]# Created time:2015 November 16 Monday 18:23 22 seconds ##################################################### #####################!/bin/bashfor x in ' ls | TR "" "_" ' dof= "' Echo ${x} | TR "_" "" ""    f1= "' echo ${x}| sed ' s/_//g '" #echo $f 1if ["$f"! = "$f 1"]thenmv "$f" "$f 1" fidone

  

Ideas:

First, the file name with a space is converted to a file name with other characters.

Then, with this file name, you get a variable with a space

Using the MV command

Shell handles files that contain spaces in the file name

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.