我试图在bash shell中编写一个处理文件的程序。我必须通过各种方式从命令行调用我的程序,以便每次都可以打印特定的列。让我们举几个例子:
./prog.sh -f file
这部分的代码是
if [[( $1 == '-f') && ( $2 == '<file>')]] ; then
echo "do stuff and print column"
我确实得到了我要打印的列,但是我也收到了以下警告:
[ - 找不到命令
有关如何删除错误的想法吗?
答案 0 :(得分:1)
确保方括号周围有空格。 [[
和]]
需要是单独的令牌。括号不添加任何内容,可以删除。 (如果你离开他们,他们也需要两边都有空格。)
if [[ $1 == '-f' && $2 == '<file>' ]]; then
echo "do stuff and print column"
fi
对于它的价值,$2
检查可能不应该存在。任何字符串都是有效的文件名。
答案 1 :(得分:-2)
您应该将文件检查重写为测试,因此您的代码将是:
Testing value -2:
Succeeded with TryParse on -2 to -2
-2 is not an underlying value of the enumeration.
Parse<TEnum> returned None
Testing value -1:
Succeeded with TryParse on -1 to -1
-1 is not an underlying value of the enumeration.
Parse<TEnum> returned None
Testing value 0:
Succeeded with TryParse on 0 to None
Converted '0' to None.
Parse<TEnum> returned None
Testing value 1:
Succeeded with TryParse on 1 to A
Converted '1' to A.
Parse<TEnum> returned A
Testing value 2:
Succeeded with TryParse on 2 to B
Converted '2' to B.
Parse<TEnum> returned B
Testing value 3:
Succeeded with TryParse on 3 to 3
3 is not an underlying value of the enumeration.
Parse<TEnum> returned None
Testing value :
Failed to TryParse on
is not a member of the enumeration.
Parse<TEnum> returned None
Testing value A:
Succeeded with TryParse on A to A
Converted 'A' to A.
Parse<TEnum> returned A
Testing value B:
Succeeded with TryParse on B to B
Converted 'B' to B.
Parse<TEnum> returned B
Testing value C:
Failed to TryParse on C
C is not a member of the enumeration.
Parse<TEnum> returned None
Testing value :
Test harness caught an exception: System.NullReferenceException: Object reference not set to an instance of an object.
at UserQuery.Main() in C:\Users\Colin\AppData\Local\Temp\3\LINQPad5\_zhvrhwll\query_ludjga.cs:line 49
is not a member of the enumeration.
Parse<TEnum> returned None