Home Corporate Contacts

TETware Knowledgebase


Products
Solutions

Information

Datasheet
Documentation
FAQ
Knowledgebase

Return to Knowledgebase Index

21. Porting Korn Shell arithmetic expressions from UNIX to Win32 systems

 

Question

I have ported a Korn Shell test case from a UNIX system to a Win32 system. When I run the test case it prints the following message:


i+=4: tp4: d:/TET/tet32/lib/ksh/tcm.ksh 678: .: create.ksh 83: not found

The file is indeed present:


-rwxrwxrwa   1 Administrators  ENG-NT\staff \
	18341 Jul 30  1997 d:/TET/tet32/lib/ksh/tcm.ksh 

Answer

I don't think that the problem is to do with the shell not being able to find tcm.ksh.

I think that you have to read the diagnostic backwards like this:

create.ksh line 83 calls tcm.ksh
tcm.ksh line 678 calls function tp4
tp4 calls i+=4
shell reports command not found

This suggests that the shell is interpreting the line i+=4 as a command whereas I expect that you intended it to be an arithmetic expression. This is because the MKS Shell is a POSIX shell and doesn't support the Korn Shell extensions by default. In the Korn Shell, you can say:


(( i+=4 ))
which is the same as saying:

let "i+=4"
But in the POSIX shell, (( i+=4 )) simply runs the command i+=4 in a subshell.

One way to write an arithmetic expression that is portable between the Korn Shell on UNIX systems and the MKS Shell on Win32 systems is:


: $(( i += 4 ))

Or you can say:


case `uname -s` in
Windows_NT|Windows_95)
	set -K
	;;
esac
to get Korn Shell behaviour from the MKS Shell on Win32 systems.

 

 


Home Contacts Legal Copyright Corporate News

Copyright © The Open Group 1995-2012, All Rights Reserved