I'm trying to add the below string manipulation commands in my existing shell script.
#!/bin/ksh y=${#text} echo "Length of text: $y" echo "Last _ is in column $((${#text} - ${#end}))" echo "Our position is till column $((${#text} - ${#end}-$x))" len=`expr $((${#text} - ${#end}-$x))` echo $len val=$( echo $text $len|awk '{print substr($0,0,$2)}') echo $val count=`ls $val*|wc -l` echo $count
The above commands works fine when executed in terminal. but when i add to my existing shell script which is running as a concurrent program, the program errors out throwing the error "Bad substitution". And i'm able to identify that the it errors out at the code added recently for string manipulations.
I can see the code is interpreted as korn shell and I've used korn shell commands only which works in terminal but when added to existing concurrent program's unix script it errors out.
Below is the code in my existing script along with newly added commands
#Parameters : Takes the following input parameters.
# 1) Input base directory -- parameter 5
# 2) File Pattern -- Parameter 6
# 3) Appl short name -- parameter 7
# 4) appl. resp. -- parameter 8
# 5) Debug -- parameter 9
#=======================================================================
#!/bin/ksh
AppsUser="$3"
BaseDir="$5"
FilePattern="$6"
AppShortName="$7"
AppResp="$8"
DebugProgram="$9"
echo "Apps User=$AppsUser"
echo "Base Directory=$BaseDir"
echo "File Pattern=$FilePattern"
echo "App Short Name=$AppShortName"
echo "App Responsibility=$AppResp"
echo "Debug Program=$DebugProgram"
IncomingDir="$BaseDir/incoming"
ProcessedDir="$BaseDir/processed"
ProcessingDir="$BaseDir/processing"
TempFile="$BaseDir/incoming/absn_psoft_glfile_search_results.txt"
ConcProgram="ABSN_PEOPLESOFT_OGL_INTF_MAIN"
echo $ConcProgram
echo $TempFile
IFS="
"
export IFS
cd $IncomingDir
ls *_GL_*.dat 1> /dev/null 2> /dev/null
if [ $? = 0 ]
then
#for i in `cat $TempFile`
for file in `ls *_GL_*.dat`
do
echo "File being processed $file"
FILENAME=$file
#echo $FILENAME
len=${#FILENAME} -->Error thrown for this command
echo "The length is $len"
if [ -s $FILENAME ]
then
echo "Moving file $FILENAME to $ProcessingDir"
mv $IncomingDir/$FILENAME $ProcessingDir/$FILENAME
echo "Submitting concurrent Request using CONCSUB for File=$FILENAME"
CONCSUB $FCP_LOGIN $AppShortName $AppResp $AppsUser WAIT=N CONCURRENT ABSN $ConcProgram $FILENAME 0 $DebugProgram $ProcessingDir
echo "Submitted Request for File=$FILENAME"
sleep 60
else
echo "File size is 0 bytes, moving file to processed directory"
mv $IncomingDir/$FILENAME $ProcessedDir/$FILENAME.rmv
fi
done
else
echo "No GL PSoft files to process."
fi
#echo "After if"
echo "Completed Job, Exiting program with code 0"
exit 0
The script is attached as an executable to an oracle concurrent program and executed using the concurrent program
ls *_GL_*.dat
do echo "File being processed $file" FILENAME=$file len=${#FILENAME} ---> error thrown here echo "The length is $len" – Dhivya Apr 13 '16 at 10:12{}
button to format it as code. – RealSkeptic Apr 13 '16 at 11:47#!/bin/ksh
! – Lucas Apr 13 '16 at 12:00