下面的代码不起作用。
我已经对所有行给出了解释:
#!/bin/ksh
cat example.txt | while read LINE # reading line from file
do
var=$LINE # assigning line to variable
echo $var # printing the line
H_OR_T="${var:0:6}" # taking substring from the line
echo $H_OR_T # printing the substring
Run Code Online (Sandbox Code Playgroud)
到这里代码工作正常。
如果 H_OR_T 变量持有硬编码值(即 M$9001,请查看下面的 if 条件)我应该进入循环。但在这里我遇到了算术错误。
if [[ $H_OR_T = "M$9001" ] || [ $H_OR_T = "M$9002" ]];
then
echo "************** MOVING HEADER OR TRAILER RECORD TO DOMESTIC FILE ************"
awk '{print $0}' example.txt > domestic.txt
else
echo "**************** …
Run Code Online (Sandbox Code Playgroud)