sab
sab

Reputation: 9977

KornShell (ksh) redirection

I have a script which redirects std out/std err as below:

SCRIPTS=/test/scripts
LOG=/test/log
echo $SCRIPTS
echo $LOG
$SCRIPTS/dmm_algo_ofac_daily_sched.ksh >> $LOG/test12.log 2>&1

This script is not able to expand $SCRIPTS and $LOG

If I replace it as below:

/test/scripts/daily_sched.ksh >> /test/log/test12.log 2>&1

It complains as below:

: bad file unit numberd/test.ksh: line 33: 1

Also I am not able to invoke the script from the directory where it is saved. If I do

./test.ksh it gives me error saying file not found. I am able to execute it via ksh /test/sched/test.ksh though.

Can someone help me with these. Thanks in advance.

Upvotes: 3

Views: 1027

Answers (3)

Jé Queue
Jé Queue

Reputation: 10637

Add magic #!/bin/ksh to the first line to invoke directly without naming the interpreter on the command line.

Upvotes: 1

Dennis Williamson
Dennis Williamson

Reputation: 360143

I'm almost certain that the problem is because of DOS/Windows line endings

The error message you are getting is overwriting itself because of a carriage return. You can fix your file using dos2unix.

Upvotes: 4

Cameron Laird
Cameron Laird

Reputation: 1075

I'll conjecture wildly that your root cause(s) has (have) nothing to do with redirection.

Is the script you've exhibited /test/sched/test.ksh or /test/scripts/test.ksh? Are you certain?

Upvotes: 0

Related Questions