Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
tc shell脚本:未定义的变量_Shell_Unix_Tcsh - Fatal编程技术网

tc shell脚本:未定义的变量

tc shell脚本:未定义的变量,shell,unix,tcsh,Shell,Unix,Tcsh,有人能告诉我set flag1有什么问题吗。。我得到一个错误flag1:未定义变量 if($notLoaded1 > 0) then echo "Rows not loaded due to data errors in first load: $notLoaded1" set flag1=1 endif if($notLoaded2 > 0) then echo "Rows not loaded due to data errors in second load: $

有人能告诉我set flag1有什么问题吗。。我得到一个错误flag1:未定义变量

if($notLoaded1 > 0) then
  echo "Rows not loaded due to data errors in first load: $notLoaded1"
  set flag1=1
endif

if($notLoaded2 > 0) then
  echo "Rows not loaded due to data errors in second load: $notLoaded2"
  set flag2=1
endif

if($notLoaded3 > 0) then
  echo "Rows not loaded due to data errors in third load: $notLoaded3"
  set flag3=1
endif

echo $flag1
echo $flag2
echo $flag3
有没有办法在一个if语句中检查所有三个if语句,而不是使用3个if语句

if ($flag1 > 0) then
  exit 1
endif

if ($flag2 > 0) then
  exit 1
endif

if ($flag3 > 0) then
  exit 1
endif

谢谢

flag1
仅在
$notLoaded1
大于0时设置。所以如果它是零,你就不会得到$flag1

我建议提前用默认值初始化这三个变量:

set flag1=0
if (...) the
    set flag1=1
    echo 'Rows not loaded...'
endif

这将保证flag1始终存在。

您需要3个标志变量做什么

set error=0

if ($notLoaded1 > 0) then
  echo "Rows not loaded due to data errors in first load: $notLoaded1"
  set error=1
endif

if ($notLoaded2 > 0) then
  echo "Rows not loaded due to data errors in second load: $notLoaded2"
  set error=1
endif

if ($notLoaded3 > 0) then
  echo "Rows not loaded due to data errors in third load: $notLoaded3"
  set error=1
endif

if ($error) then
  exit 1
endif