Operating System - HP-UX
1834293 Members
2150 Online
110066 Solutions
New Discussion

Re: script problem in reading parm file

 
SOLVED
Go to solution
Chun Boon Lee
New Member

script problem in reading parm file

portion of the script:

#!/bin/sh
. test.ini
cp $param_file2 $param_file_bak2

cat $param_file2 > a.log
echo "----below is the reading value ------" >> a.log
for i in `cat $param_file2`
do
echo $i
echo $i >> a.log
done > tparam_file

Output:
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_22]
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_2]
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_11]
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_AA]
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_A]
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_A1]

----below is the reading value ------
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_22]
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_2]
1
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_AA]
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_A]
1

We found out that there is a file name "1" in the same directory as the script.

Any idea how to over come this?

thanks
8 REPLIES 8
Peter Godron
Honored Contributor

Re: script problem in reading parm file

Hi,
can first check that the filenames are ok with:
ls -b PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_*
This should eliminate any filename corruption.
Secondly why do you have a "> tparam_file"
at the end of your loop?
Regards
Slawomir Gora
Honored Contributor

Re: script problem in reading parm file

Hi,

try to use while loop instead of for

syntax:
cat $param_file2 | while read
do
i=$REPLY
echo $i
echo $i >> a.log
done
Chun Boon Lee
New Member

Re: script problem in reading parm file

If I remove the file 1, the output is ok. If I touch a file A, then the the output become:
PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_22]
[PD_ODS.s_m_FHOPEHS_TO_ODS_OTHERS_ALL_2]
1
A
A
1

somehow there cannot have a file with a letter or number same as the end of output in the same directory as the script.

This script is a portion of the application script.
Stephen Keane
Honored Contributor

Re: script problem in reading parm file

What is in test_ini ?
Chun Boon Lee
New Member

Re: script problem in reading parm file

test.ini content

param_file2="p.txt"
param_file_bak2="p.bak"

john korterman
Honored Contributor

Re: script problem in reading parm file

Hi,
I would assume that the problem is that the shell performs file name substitution in the current directory. The cure is to qoute the regular expressions in the script.
You say that it is a portion of the script; typical places to look for culprits are square brackets, e.g. [a-z] and asterisks.
Try double qouting.

regards,
John K.
it would be nice if you always got a second chance
Stephen Keane
Honored Contributor
Solution

Re: script problem in reading parm file

Change your script to ...

#!/bin/sh
. test.ini
cp $param_file2 $param_file_bak2

cat $param_file2 > a.log
echo "----below is the reading value ------" >> a.log
set -f
for i in `cat $param_file2`
do
echo $i
echo $i >> a.log
done > tparam_file
set +f
Chun Boon Lee
New Member

Re: script problem in reading parm file

Thanks very much, I had solved the problem using the set -f and set +f