3

I want to find all *.sh files in some directory, but there are some errors in the script...

#!/bin/sh
for plik in /var/panel/starter/*
do  
    if [ $(basename "$plik") != "priority" ] && [ $(basename "$plik") != "PRIORITY" ] 
    then
    for plik in $plik/*
    do
        filename=$(basename "$plik")
        extension="${filename##*.}"
        filename="${filename%.*}"
        if [ "$extension" == "sh" ]
        then
        echo $plik
        fi
    done
    fi
done 

There are some folders in /var/panel/starter, and in these folders there are shell scripts that's why I used for loop twice.

This is the error:

[: 19: *: unexpected operator
[: 19: sh: unexpected operator
[: 19: sh: unexpected operator
[: 19: sh: unexpected operator
[: 19: *: unexpected operator

I guess the problem is with empty folders like:

/var/panel/starter/cs16/*

and I don't have an idea how to deal with that.

4

3 回答 3

14

为什么要使用脚本,什么时候可以使用:

find path_to_folder -iname "*.sh"
于 2013-08-06T14:29:25.083 回答
3

sh: unexpected operator应该给你一个线索。

您正在使用sh不支持第==19 行的运算符执行脚本。使用执行脚本bash应该可以正常工作,或者只使用=.

于 2013-08-06T14:24:54.263 回答
1

为什么不使用 find 和 grep?

find /var/panel/starter/ -name "*.sh" | grep -iv "/var/panel/starter/priority"
于 2013-08-06T14:24:10.870 回答