发现工作不正常

km
if [[ "$1" == "" ]]
 then

leftarray=($(find . -type l -printf "%p\n" 2>/dev/null))
rightarray=($(find . -type l -printf "%l\n" 2>/dev/null))

for var in "${rightarray[@]}"
do
   maximumarray[$index]=`echo "$var" | tr -dc "/" | wc -c | tr -d " "`
   index=$(($index+1))
done
#############
for numbers in "${maximumarray[@]}"
do
   if [[ $numbers > $MAX  ]]
   then
   MAX=$numbers
   fi
done
#############
for var in "${rightarray[@]}"
do

   component=`echo "$var" |  tr -dc "/" | wc -c | tr -d " "`
        if [[ $component -eq $MAX  ]]
        then
        echo "Output: '${leftarray[$temp]} -> ${rightarray[$temp]}'"
        fi
   emp=$(($temp + 1))
done

这是问题所在,当运行不带参数或开关的脚本时,它应搜索您所在目录的所有目录和子目录。它不起作用,我也不知道为什么,这使我发疯。

该脚本应找到"/"in最长的符号链接-printf "%l\n"并将其输出。当有更多相同数量的“ /”链接时,它应该工作

这个脚本也有切换,-d <number>并且它具有与上面相同的代码,但是在查找中我也使用了-maxdepth并且它可以正常工作,所以我不知道为什么这不起作用。

有什么帮助吗?

蒂莫西·马丁(Timothy Martin)

根据OP提供的其他信息,解决方案便是这样。

有条件的行if [[ $numbers > $MAX ]]不能产生期望的结果。通过将更>改为-gt脚本,可以按预期工作。

在条件表达式下的bash联机帮助页中:

string1 > string2
          True if string1 sorts after string2 lexicographically in the current locale.

arg1 OP arg2
       OP is one of -eq, -ne, -lt, -le, -gt, or -ge.  These arithmetic binary operators return true if arg1  is  equal  to,  not
          equal  to, less than, less than or equal to, greater than, or greater than or equal to arg2, respectively.  Arg1 and arg2
          may be positive or negative integers.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章