Bash rename extension recursive

后端 未结 6 1583
-上瘾入骨i
-上瘾入骨i 2020-12-29 09:32

I know there are a lot of things like this around, but either they don\'t work recursively or they are huge.

This is what I got:

find . -name \"*.so\         


        
6条回答
  •  梦谈多话
    2020-12-29 10:15

    He needs recursion:

    #!/bin/bash
    
    function walk_tree {
        local directory="$1"
        local i
    
        for i in "$directory"/*; 
            do
                if [ "$i" = . -o "$i" = .. ]; then 
                    continue
                elif [ -d "$i" ]; then  
                walk_tree "$i"  
                elif [ "${i##*.}" = "so" ]; then
                    echo mv $i ${i%.*}.dylib    
                else
                    continue
                fi
            done    
    }
    
    walk_tree "."
    

提交回复
热议问题