Home > Software design >  shell list All Xcode xcworkspace and xcodeproj
shell list All Xcode xcworkspace and xcodeproj

Time:08-15

I want to list project directory all xcworkspace and xcodeproj file.

And I write code below

#!/bin/bash

workspaceFile="xcworkspace"
projectFile="xcodeproj"

#listFiles 
path=$(pwd)

fileList=()

walk_dir () {
    for name in "$path"/*; do
        if [[ -d "$name" && ("${name##*.}" != ${projectFile} || "${name##*.}" != ${workspaceFile}) ]]; then
            path=$name
            walk_dir "$name"
        else 
            if [ "${name##*.}"x = ${workspaceFile}x ] || [ "${name##*.}"x = ${projectFile}x ];then
                fileList =($name)
            fi
        fi
    done
}

walk_dir

for name in ${fileList[@]}; do
    echo $name
done

It did not work.

But If change the condition, like below

        if [[ -d "$name" && ("${name##*.}" != ${workspaceFile}) ]]; then
            path=$name
            walk_dir "$name"
        else 
            if [ "${name##*.}"x = ${workspaceFile}x ] || [ "${name##*.}"x = ${projectFile}x ];then
                fileList =($name)
            fi
        fi

or

        if [[ -d "$name" && ("${name##*.}" != ${projectFile}) ]]; then
            path=$name
            walk_dir "$name"
        else 
            if [ "${name##*.}"x = ${workspaceFile}x ] || [ "${name##*.}"x = ${projectFile}x ];then
                fileList =($name)
            fi
        fi

It works also.

I want to keep filter xcworkspace and xcodeproj.

Someone can help me?

CodePudding user response:

Finaly, I found result by myself.

#!/bin/bash

workspaceFile="xcworkspace"
projectFile="xcodeproj"

path=$1
fileList=()

projectList () {
    for name in "$path"/*; do
        if [ -d "$name" ] && [ "${name##*.}"x = ${workspaceFile}x ]; then
            fileList =(${name})
        elif [ -d "$name" ] && [ "${name##*.}"x = ${projectFile}x ]; then
            fileList =(${name})
        elif [ -d "$name" ]; then
            path=$name
            projectList
        fi
    done
}


projectList


for name in ${fileList[@]}; do
    echo "xcode project: $name"
done
  • Related