脚本抛出错误“=:未找到”

Man*_*mar 4 ksh shell-script

考虑:

#!/bin/ksh

db2 connect to MKTETLPS user ....... using ........

db2 "select count(*)  from etl.IDM_COLLAPSE_ORG_DEE c where c.IDM_PROCESS_STEP = 'I' and priority in ( '1','2','3','4','5') and c.update_ts < (current timestamp - 60 minutes) with ur"  > l.txt

$a = /is115/idm/dsproj/scripts/l.txt

        if [ $a -gt 0 ];
      then
        db2  "update etl.idm_collapse_org_dee
             set idm_process_step = NULL where priority in (
'1','2','3','4','5')
             and idm_process_step ='I'"
      else
          echo "All is well"
fi
Run Code Online (Sandbox Code Playgroud)

我在脚本上方运行并收到以下错误。我该如何解决?

./CORCleanup1.sh[8]: =:  not found.
./CORCleanup1.sh[10]: test: 0403-004 Specify a parameter with this command.
All is well
DB20000I  The SQL command completed successfully.
DB20000I  The TERMINATE command completed successfully.

db2 connect reset


db2 terminate
exit
Run Code Online (Sandbox Code Playgroud)

Tho*_*mas 11

变量赋值不能包括$和 周围的空格=。我也会双引号作业。所以变量赋值应该如下所示。

a="/is115/idm/dsproj/scripts/l.txt"
Run Code Online (Sandbox Code Playgroud)

通过进一步阅读脚本,您似乎更愿意将文件内容存储1.txt在其中$a而不是文件路径本身。为此,您可以按如下方式使用分配。

read -r a < /is115/idm/dsproj/scripts/l.txt
Run Code Online (Sandbox Code Playgroud)

read -r读取文件的第一行,去除前导和尾随空格和制表符(假设默认值为$IFS)并将其存储在提供的变量中)


您可能还想$aif语句中对变量加双引号。

if [ "$a" -gt 0 ];
Run Code Online (Sandbox Code Playgroud)

您还可以使用https://www.shellcheck.net/检查脚本的语法。