Hi,
I'm playing with ksh. I'm trying to do a simple task:
read file name from cli and call a function which calculated number of lines in file.
I'm getting coredump every time when I try to read that file.
Korn shell version
$ print ${.sh.version}
Version AJM 93u+ 2012-08-01
Main program
#!/bin/ksh -x
# Read input file from cli and
# perform some simple awk manipulations
### Include aliases types ###
. ./talias
# Used variables
inputFile=
integer NumberOfRecords=0
### Script functions #######
FPATH=/home/dev/ksh
autoload GetNumberOfRecords
while getopts :f:a Flag
do
case ${Flag} in
a)
print "${inputFile}"
GetNumberOfRecords inputFile
;;
f)
if [ -r ${OPTARG} ]
then
print "${OPTARG} exists"
inputFile=${OPTARG}
fi
;;
\?)
print -R "'${OPTARG}' - unkown flag"
print "${Usage}"
;;
:)
print -R "'-f' requires a value, specify input name"
exit 2
;;
esac
done
function name (stored in file with same name in /home/dev/ksh)
GetNumberOfRecords
{
Input=${1}
print "Input FIle is ${Input}"
while read Line
do
print "${Line}"
done < ${Input}
print "Total rows for ${Input} is ${NumberOfRows}"
}
talias is file with alias for integer
alias integer='typeset -i'
Debug output
+ . ./talias
+ alias integer='typeset -i'
+ inputFile=''
+ NumberOfRecords=0
+ typeset -i NumberOfRecords
+ FPATH=/home/dev/ksh
+ typeset -fu GetNumberOfRecords
+ getopts :f:a Flag
+ [ -r emp.data ]
+ print 'emp.data exists'
emp.data exists
+ inputFile=emp.data
+ getopts :f:a Flag
+ print emp.data
emp.data
Segmentation fault (core dumped)