Error after I added several lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error after I added several lines
# 1  
Old 03-28-2017
Error after I added several lines

I have added several lines to my code
Code:
 let cnt=0
  if [ ${sftp_name} = "EOMMSRPT" ]
        then
                if [ ${cnt} -eq 0 ]
                then
                        cnt=`expr ${cnt} + 1`
                        sftp_name=EOMMSRPT1
                        echo "EOMsftpname = ${sftp_name}" >> ${LOGF}
                else
                        sftp_name=EOMMSRPT2
                        echo "EOMsftpname = ${sftp_name}" >> ${LOGF
                fi
  fi

Now when I run the script, it has an error
Code:
 /sftp_ondemand_monthly.sh[76]: syntax error at line 150 : `>' unexpected

What should wrong with it?

Thanks for contribution

---------- Post updated at 01:26 PM ---------- Previous update was at 01:17 PM ----------

Found the problem
Code:
 echo "EOMsftpname = ${sftp_name}" >> ${LOGF

must be the second
Code:
 ${LOGF}

This User Gave Thanks to digioleg54 For This Post:
# 2  
Old 03-28-2017
Yep, you caught it I think.

FYI, in a modern shell, you can do CNT=$((CNT+1)) or even ((CNT++)) to add a number, the expr syntax is very old.
# 3  
Old 03-28-2017
Yes, expr is an external program; the builtin $(( )) is much more efficient.
And in an if [ ${cnt} -eq 0 ]; then you can even do cnt=1.
Further, you can redirect a whole code block like this
Code:
  if [ ${cnt} -eq 0 ]
  then
    cnt=1
    sftp_name=EOMMSRPT1
    echo "EOMsftpname = ${sftp_name}"
  else
    sftp_name=EOMMSRPT2
    echo "EOMsftpname = ${sftp_name}"
  fi >> $LOGF

And in this case of course
Code:
  if [ ${cnt} -eq 0 ]
  then
    cnt=1
    sftp_name=EOMMSRPT1
  else
    sftp_name=EOMMSRPT2
  fi
  echo "EOMsftpname = ${sftp_name}" >> $LOGF

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Added Two Arrays But With Errors

Please could someone have a look at the code below and spot the cause of the error. Thanks in advance. CODE BELOW: (code tags now added) My apologies please, that was my first time here.:) #! /bin/bash # file: whileloop.sh arr1=(2 4 6 8) arr2=(3 6 9 12) arr3=() indextotal=(${#arr1})... (4 Replies)
Discussion started by: Chiadi
4 Replies

2. AIX

LPAR cannot added disk

Dear All, I created a new partition through "Integrated Virtualization Manager" but there have an error when I added a new disk to the partition. The disk already created without any issue, Below error is to add the disk to the partition An error occured while modifying the assignments... (5 Replies)
Discussion started by: lckdanny
5 Replies

3. Red Hat

Static route not added

Hello Guys.. I am facing this weird problem of static route not added after reboot!! Following is my route-<interface> file.. # cat /etc/sysconfig/network-scripts/route-eth0 ADDRESS0=172.31.0.1 NETMASK0=255.255.255.255 GATEWAY0=192.168.208.1 ADDRESS1=172.31.15.2... (3 Replies)
Discussion started by: parth_buch
3 Replies

4. UNIX for Dummies Questions & Answers

Perl: added to an element

I'm trying to add a string to the end of each element in an array. I have filled an array using grep: for ($i = 0; $i <= $#array} - 1; $i++) { push (@data,qx(grep '$array' $file)); } } Now i want to add something to the end of the array. For example if my... (3 Replies)
Discussion started by: WongSifu
3 Replies

5. Shell Programming and Scripting

Unique value added

Guys, I am trying to get unique numbers which i can use as a primary key in a table. I tried using the <seconds_since_epoch>.<hostname> combination but since more than one process can run on the same machine at the same time, this won't be unique either. Can anyone tell me another way to do... (2 Replies)
Discussion started by: garric
2 Replies

6. UNIX for Dummies Questions & Answers

Routes being automatically added

Hello, I have two AIX 5.3 servers that are supposedly set up exactly the same. The problem I am having is on one of the servers, it seems dynamic routes are being added mysteriously and non-periodically. This only happens on one server and not the other. Also, there doesn't seem to be a specific... (1 Reply)
Discussion started by: Conutmonky
1 Replies

7. Programming

How come nothing is added to utmp in this case?

Given the following: #include <string.h> #include <stdlib.h> #include <pwd.h> #include <unistd.h> #include <utmp.h> #include <stdio.h> #include <time.h> int main(int argc, char *argv) { struct utmp entry; char *fd; system("echo before adding entry:;who"); ... (1 Reply)
Discussion started by: frequency8
1 Replies

8. Shell Programming and Scripting

New Person Added to the Forum

Hello, I'm brand new to this forum. I am working on my first Bash shell script. We were given an exercise to get ready for the real assignment. I could use some help. The exercise is to "set two variables (i. e., file1 & file2) on the command line to the paths of the text files. We are to... (1 Reply)
Discussion started by: wcarp05
1 Replies

9. UNIX for Dummies Questions & Answers

How to scan only new lines added in file?

Hi, I am planning to implement a scheduled script that will go against my log files (every hour), search for a set of key words (errors, exceptions, faults etc). The script must be intelligent enough to scan only the new lines added to the log file since it last ran. I can use grep for... (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question