How to execute korn shell script from different directory

Guy's ,
I need to run korn shell script from different directory, usually I run the script using ./details.ksh in the same directory but now I need to run the file and process details using awk code.
Now I am running the script this way but with no luck

  Directory = home/users/work 
   
    ${Directory}/details.ksh| awk '
      {
          gsub( ">", "" );        # strip uneeded junk and make "foo bar" easy to capture
          gsub( " ", "~" );
          gsub( "<", " " );
   
          for( i = 1; i <= NF; i++ )          # snarf up each name=value pair
          {
              if( split( $(i), a, "=" ) == 2 )
              {
                  gsub(  "\"", "", a[2] );
                  gsub(  "~", " ", a[2] );
                  values[a[1]] = a[2];
              }
          }
   
          #gcount[values["Gender"]]++;         # collect counts
          #acount[values["Age"]]++;
          agcount[values["Gender"]","values["Age"]]++;
   
          printf( "%s %s %s %s\n", values["NAME"], values["Age"], values["D.O.B"], values["Gender"] );
      }
   
      END {
          printf( "\nSummary\n" );
          for( x in agcount )
              printf( "%s,%d\n", x, agcount[x] ) | "sort";
      }
  ' input-file
     

This code is in different directory i.e.

home/TestDir/awkwork 
  

Can I please get help with this?
Any help is appreciated.

If you have execute permissions on the script you should be able to run it.
It looks like your missing the first "/" in your path.. Try
Directory="/home/users/work/"

1 Like

Thank you BeefStu,

The problem was with the file permission, but is there a way to change output file permission within the the code.

chmod 777 the output file within the code. 

you can try running this way... may not need to use chmod..

ksh /home/TestDir/awkwork/details.ksh

[@CentOS1 ~]$ pwd
/home/xxx
[@CentOS1 ~]$

[@CentOS1 ~]$ sh /tmp/sh.sh
hello

[@CentOS1 ~]$ cat /tmp/sh.sh

echo "hello"

-rw-r--r-- 1 binku users 15 Dec 15 06:05 /tmp/sh.sh