0

i have batch file, and i dont know about shell scripts. Can someone please help here.

      @echo off
      echo "Program Name               :" %0
      rem  echo "Next param            :" %1
      echo "Next param                 :" "Username/Password"
      echo "User Id                    :" %2
      echo "User Name                  :" %3
      echo "Request ID                 :" %4
      echo "File Name                  :" %5 
      echo "Entity Name                :" %6
      echo "Email Address              :" %7
      echo "Extract ID                 :" %8
      echo "path name                  :" %9

  cd %9

 echo "Process Output files"
 IF NOT EXIST C:\OraOutput GOTO MAPERROR
 IF EXIST o%8.out (COPY o%8.out %5.csv) ELSE echo "Output file does not exists"
 IF EXIST %5.csv (MOVE %5.csv C:\OraOutput\%5.cvs) ELSE echo "Could not move file to   Share Drive"
 GOTO ENDPROCESS
 :MAPERROR
 echo "The Share Directory has not been mapped Contact your System Administrator"
 EXIT -1
 :ENDPROCESS
 echo "Process finished goodbye"

Thanks.

  • Read any [shell tutorial](http://www.grymoire.com/Unix/Sh.html), try to write the script, come here with a specific question. – khachik Feb 26 '13 at 07:44
  • when I see this question, on the right side I see many similar questions that you can refer to. – FooF Feb 26 '13 at 08:00

1 Answers1

0

I am assuming more or less Bourne compatible shell like bash as this is most common. To get started, here's some differences that you need understand in order to transform your batch script to Bourne style shell script:

  1. The first difference is that the executed commands are by default not echoed (though you can change this).
  2. Comments begin with hash character #.
  3. cd and echo and exit also exists in Bourne compatible shells.
  4. To test for file existence, you can use [ -e file-name ].
  5. IF statement becomes if condition ; then true-statement ; else false-statement ; fi where you can have multiple commands / statements separated by semicolons in place of true-statement and false-statement.
  6. IF EXIST o%8.out (COPY o%8.out %5.csv) ELSE echo "Output file does not exists" in Bourne compatible shell would look like

    # I am assuming %8 means parameter 8 for the script
    if [ -e o$8.out ]; then cp o$8.out $5.csv; else echo "Output file does not exist"; fi
    

    or with alternative indentation (semicolon can be replaced with new line):

    if [ -e o$8.out ]; then
        cp "o$8.out" "$5.csv"
    else
        echo "Output file does not exist"
    fi
    

    note that we also quote the arguments to cp so that we can use spaces in the arguments.

  7. You can get rid of the goto by little restructuring. You can refer to this Stack Overflow question (assuming bash or other Bourne shell style script dialect): Is there a "goto" statement in bash?
Community
  • 1
  • 1
FooF
  • 4,323
  • 2
  • 31
  • 47