Matching folder name using bash

孤街浪徒 提交于 2019-12-24 00:58:01

问题


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


回答1:


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

Use, e.g.:

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


来源:https://stackoverflow.com/questions/56821197/matching-folder-name-using-bash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!