HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Problem with Korn Shell Script
Operating System - HP-UX
1839415
Members
3669
Online
110145
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2004 05:04 AM
11-01-2004 05:04 AM
Problem with Korn Shell Script
Hello All:
I need your help again. Any suggestions will be much appreciated.
The script below used to work up until a week ago. The only change to the environment is a new version of Server Express (cobol compiler) was installed. I didn't think this would affect anything though. The problem appears in the "rm" logic.
This script rips through a directory looking for all programs that begin with "i" and end in ".pco". It removes all the compile-generated files and recreates them with the compile process. The original files are: ioparm.pco, ioparm2.pco, ioparm3.pco, ioparm4.pco, and ioparm5.pco. One one system it processes the files in the order ioparm, ioparm2, ioparm3, then 4, then 5. On Another it reverses the order and when it comes to the ioparm program, not only does it delete the ioparm files, it delete the files generated for ioparm2-3-4-5. Can you think of a reason why it is processing the files in a different order now? Thank you in advance.
#!/bin/ksh
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Compile all embedded SQL programs.
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"|tee -a compile.log
echo " COMPILATION OF COBOL/SQL SOURCE CODE"|tee -a compile.log
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"|tee -a compile.log
echo `date`|tee -a compile.log
cp ascii.dir cobol.dir
export _rtncode=`echo $?`
case $_rtncode in
0) ;;
*) echo Setup for compilation of embedded SQL programs ERROR!!!!!!!!|tee -a compile.log ;
echo SCRIPT TERMINATED ! COMPILES UNSUCCESSFUL !|tee -a compile.log ;
exit ;;
esac
for i in $(echo *.pco)
do
echo ""|tee -a compile.log
_name=${i%.*}
for j in $_name*
do
if [[ $j != *.pco ]]
then
rm -f $j
fi
done
make -f procob.mk build COBS=${i%%.*}.cob EXE=${i%%.*} >$i.err 2>&1
export _rtncode=`echo $?`
case $_rtncode in
0) echo $i successful compilation.......|tee -a compile.log ;;
*) echo $i did NOT compile!!!!!! Errors exist!!!! |tee -a compile.log ;;
esac
echo ""|tee -a compile.log
done
I need your help again. Any suggestions will be much appreciated.
The script below used to work up until a week ago. The only change to the environment is a new version of Server Express (cobol compiler) was installed. I didn't think this would affect anything though. The problem appears in the "rm" logic.
This script rips through a directory looking for all programs that begin with "i" and end in ".pco". It removes all the compile-generated files and recreates them with the compile process. The original files are: ioparm.pco, ioparm2.pco, ioparm3.pco, ioparm4.pco, and ioparm5.pco. One one system it processes the files in the order ioparm, ioparm2, ioparm3, then 4, then 5. On Another it reverses the order and when it comes to the ioparm program, not only does it delete the ioparm files, it delete the files generated for ioparm2-3-4-5. Can you think of a reason why it is processing the files in a different order now? Thank you in advance.
#!/bin/ksh
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# Compile all embedded SQL programs.
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"|tee -a compile.log
echo " COMPILATION OF COBOL/SQL SOURCE CODE"|tee -a compile.log
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"|tee -a compile.log
echo `date`|tee -a compile.log
cp ascii.dir cobol.dir
export _rtncode=`echo $?`
case $_rtncode in
0) ;;
*) echo Setup for compilation of embedded SQL programs ERROR!!!!!!!!|tee -a compile.log ;
echo SCRIPT TERMINATED ! COMPILES UNSUCCESSFUL !|tee -a compile.log ;
exit ;;
esac
for i in $(echo *.pco)
do
echo ""|tee -a compile.log
_name=${i%.*}
for j in $_name*
do
if [[ $j != *.pco ]]
then
rm -f $j
fi
done
make -f procob.mk build COBS=${i%%.*}.cob EXE=${i%%.*} >$i.err 2>&1
export _rtncode=`echo $?`
case $_rtncode in
0) echo $i successful compilation.......|tee -a compile.log ;;
*) echo $i did NOT compile!!!!!! Errors exist!!!! |tee -a compile.log ;;
esac
echo ""|tee -a compile.log
done
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2004 09:45 AM
11-01-2004 09:45 AM
Re: Problem with Korn Shell Script
Is it at all possible that a "set -f" was done somewhere before hand?
This turns off filename "glob"ing which I notice certain statements behave very strangely.
my 2 cents
-- Rod Hills
This turns off filename "glob"ing which I notice certain statements behave very strangely.
my 2 cents
-- Rod Hills
There be dragons...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2004 09:46 PM
11-01-2004 09:46 PM
Re: Problem with Korn Shell Script
Hi,
This bit of code in your script is the problem...
for i in $(echo *.pco)
do
echo ""|tee -a compile.log
_name=${i%.*}
for j in $_name*
do
if [[ $j != *.pco ]]
then
rm -f $j
fi
done
The '$(echo *.pco)' bit provides you with a list of ALL files in the current directory ending .pco. Note these could be in any order and you are NOT limiting the selection to files starting with "i".
'_name=${i%.*}' simply strips off the ".pco" from the end of the filename so you are left with ioparm, ioparm2 etc.
This bit...
for j in $_name*
do
if [[ $j != *.pco ]]
then
rm -f $j
fi
is attempting (I believe) to remove all files whose name starts with that in $_name which doesn't end in .pco. However the statement:
if [[ $j != *.pco ]]
is causing your problem as *.pco will be expanded by the shell and can't be guaranteed to work correctly.
You could try something like the following...
TMP=tmp.${$} # an arbitrary temp filename
for i in $(ls i*.pco)
do
_name=${i%.*} # remove the .pco
# temp rename the file we want to keep
mv ${i} ${TMP}
# remove all other files
rm -f ${_name}*
# reinstate the original .pco filename
mv ${TMP} ${i}
make -f procob.mk build COBS=${_name}.cob EXE=${_name} >${i}.err 2>&1
Hope this helps.
Regards,
John
This bit of code in your script is the problem...
for i in $(echo *.pco)
do
echo ""|tee -a compile.log
_name=${i%.*}
for j in $_name*
do
if [[ $j != *.pco ]]
then
rm -f $j
fi
done
The '$(echo *.pco)' bit provides you with a list of ALL files in the current directory ending .pco. Note these could be in any order and you are NOT limiting the selection to files starting with "i".
'_name=${i%.*}' simply strips off the ".pco" from the end of the filename so you are left with ioparm, ioparm2 etc.
This bit...
for j in $_name*
do
if [[ $j != *.pco ]]
then
rm -f $j
fi
is attempting (I believe) to remove all files whose name starts with that in $_name which doesn't end in .pco. However the statement:
if [[ $j != *.pco ]]
is causing your problem as *.pco will be expanded by the shell and can't be guaranteed to work correctly.
You could try something like the following...
TMP=tmp.${$} # an arbitrary temp filename
for i in $(ls i*.pco)
do
_name=${i%.*} # remove the .pco
# temp rename the file we want to keep
mv ${i} ${TMP}
# remove all other files
rm -f ${_name}*
# reinstate the original .pco filename
mv ${TMP} ${i}
make -f procob.mk build COBS=${_name}.cob EXE=${_name} >${i}.err 2>&1
Hope this helps.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2004 02:01 AM
11-02-2004 02:01 AM
Re: Problem with Korn Shell Script
John,
Wild card expansion does return a sorted list. You stated-
"The '$(echo *.pco)' bit provides you with a list of ALL files in the current directory ending .pco. Note these could be in any order and you are NOT limiting the selection to files starting with "i"."
From "man ksh"-
The form of the patterns is the Pattern Matching Notation defined by regexp(5).
The word is replaced with sorted file names matching the pattern. If no file name is found that matches the pattern, the word is left unchanged.
Also, I think the [[ ]] are magical in that file name expansion does not occur. You state-
if [[ $j != *.pco ]]
is causing your problem as *.pco will be expanded by the shell and can't be guaranteed to work correctly.
From "man ksh"-
A conditional expression is used with the [[ compound command to test attributes of files and to compare strings.
Word splitting and file name generation are not performed on the words between [[ and ]].
I first assumed what you did until and I tried them out and checked "man ksh". I'm still wondering "glob"ing got turned off...
-- Rod Hills
Wild card expansion does return a sorted list. You stated-
"The '$(echo *.pco)' bit provides you with a list of ALL files in the current directory ending .pco. Note these could be in any order and you are NOT limiting the selection to files starting with "i"."
From "man ksh"-
The form of the patterns is the Pattern Matching Notation defined by regexp(5).
The word is replaced with sorted file names matching the pattern. If no file name is found that matches the pattern, the word is left unchanged.
Also, I think the [[ ]] are magical in that file name expansion does not occur. You state-
if [[ $j != *.pco ]]
is causing your problem as *.pco will be expanded by the shell and can't be guaranteed to work correctly.
From "man ksh"-
A conditional expression is used with the [[ compound command to test attributes of files and to compare strings.
Word splitting and file name generation are not performed on the words between [[ and ]].
I first assumed what you did until and I tried them out and checked "man ksh". I'm still wondering "glob"ing got turned off...
-- Rod Hills
There be dragons...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP