下面的shellcript是什么错误,因为我得到错误" fi"运行此脚本时?

时间:2016-02-29 07:25:05

标签: linux shell unix

fileloc=/shellscript/ScriptDeleteLogs/Testfiles/Testdata/*
for fname in fileloc
do
name=$(basename "$fileloc")
if [ $name = $omitfiles ] then
echo $name
fi
done

我正在尝试从目录中获取文件名但是当我应用过滤器时,即如果条件它会引发错误,即语法错误接近意外令牌' fi'然后'然后' 格式化条件:

if [ "$name" != "$omitfiles" ]; then echo $name fi

1 个答案:

答案 0 :(得分:3)

在if条件之后插入换行符:

module NeedPositiveFoo
  def included(other)
    raise unless defined?(@@foo) && @@foo > 0
  end
end

class ValidClass
  @@foo = 3
  include NeedPositiveFoo
end

class InvalidClass1
  # @@foo is not defined
  include NeedPositiveFoo
end

class InvalidClass2
  @@foo = -2
  include NeedPositiveFoo
end

class InvalidClass3
  include NeedPositiveFoo

  @@foo = 4 # declared after inclusion - not a valid state...
end

或者在条件之后加上分号:

...
if [ "$name" = "$omitfiles" ]
then
...

当然,条件中的变量应该是双引号。