简体   繁体   中英

Matching folder name using bash

I have this piece of code to match the folder name:

#!/bin/bash
for dir in teste/* 
do 
    if [ "$dir" = 1 ]; then 
        echo "folder 1"; 
    fi
    if [ "$dir" = 2 ]; then
        echo "folder 2";
    fi
done

And I have a directory called teste/1/ and teste/2/ After running the script above, my output is nothing! There are no errors...

Do you know how to solve it? I don't know why this happens

Variable dir does not contain 1 or 2 but teste/1 or teste/2 .

Use, eg:

if [ "$dir" = "teste/1" ]; then 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM