Shell variables set inside while loop not visible outside of it

后端 未结 4 1180
抹茶落季
抹茶落季 2020-11-28 06:02

I am trying to find the pathname with the most characters in it. There might be better ways to do this. But I would like to know why this problem occurs.

LO         


        
4条回答
  •  醉梦人生
    2020-11-28 06:42

    About finding the longest pathname. Here's an alternative:

    find /usr/share/zoneinfo | while read line; do
        echo ${#line} $line 
    done | sort -nr | head -n 1
    
    # Result:
    58 /usr/share/zoneinfo/right/America/Argentina/ComodRivadavia
    

    Forgive me if this is considered off topic, I hope it helps someone.

提交回复
热议问题