HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Script problem
Operating System - HP-UX
1832398
Members
3083
Online
110041
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
02-02-2010 08:23 AM
02-02-2010 08:23 AM
Shell Script problem
I have a find command that is being dynamically built then executed with a sub shell within a for loop.
The problem is the sub shell is single quoting all the escaped characters....
Below is a code snippet:
FINDPARM="\( -type f "
for SUFFIX in $(echo $PWDSRCH_EXCLUDE_FILE_SUFFIX|tr -s ',' ' ')
do
FINDPARM="$FINDPARM -a ! -name \"*.$SUFFIX \""
done
for EXCLUDE in $(echo $PWDSRCH_EXCLUDE_FILE|tr -s ',' ' ')
do
FINDPARM="$FINDPARM -a ! -name \"*$EXCLUDE* \""
done
FINDPARM="$FINDPARM \)"
GREPPARM=" -il"
for STRING in $PASSWDS
do
GREPPARM="$GREPPARM -e $STRING"
done
for FILE in `find $FINDROOT $FINDPARM -exec grep $GREPPARM {} \;`
The script errors out with the following display in debug (BTW - if I echo the command all looks good)
[28]: FINDPARM='\( -type f -a ! -name "*.so " -a ! -name "*.sl " -a ! -name "*.iso " -a ! -name "*.dbf " -a ! -name "*.tif " -a ! -name "*.dmp " -a ! -name "*.core " -a ! -name "*.html " -a ! -name "*.htm " -a ! -name "*.shtml " -a ! -name "*.db " -a ! -name "*.prn " -a ! -name "*redo* " \)'
[30]: GREPPARM=' -il'
[33]: GREPPARM=' -il -e trace'
[33]: GREPPARM=' -il -e trace -e test'
[33]: find / '\(' -type f -a ! -name '"*.so' '"' -a ! -name '"*.sl' '"' -a ! -name '"*.iso' '"' -a ! -name '"*.dbf' '"' -a ! -name '"*.tif' '"' -a ! -name '"*.dmp' '"' -a ! -name '"*.core' '"' -a ! -name '"*.html' '"' -a ! -name '"*.htm' '"' -a ! -name '"*.shtml' '"' -a ! -name '"*.db' '"' -a ! -name '"*.prn' '"' -a ! -name '"*redo*' '"' '\)' -exec grep -il -e trace -e test '{}' ';'
find: missing conjunction
Any Ideas
The problem is the sub shell is single quoting all the escaped characters....
Below is a code snippet:
FINDPARM="\( -type f "
for SUFFIX in $(echo $PWDSRCH_EXCLUDE_FILE_SUFFIX|tr -s ',' ' ')
do
FINDPARM="$FINDPARM -a ! -name \"*.$SUFFIX \""
done
for EXCLUDE in $(echo $PWDSRCH_EXCLUDE_FILE|tr -s ',' ' ')
do
FINDPARM="$FINDPARM -a ! -name \"*$EXCLUDE* \""
done
FINDPARM="$FINDPARM \)"
GREPPARM=" -il"
for STRING in $PASSWDS
do
GREPPARM="$GREPPARM -e $STRING"
done
for FILE in `find $FINDROOT $FINDPARM -exec grep $GREPPARM {} \;`
The script errors out with the following display in debug (BTW - if I echo the command all looks good)
[28]: FINDPARM='\( -type f -a ! -name "*.so " -a ! -name "*.sl " -a ! -name "*.iso " -a ! -name "*.dbf " -a ! -name "*.tif " -a ! -name "*.dmp " -a ! -name "*.core " -a ! -name "*.html " -a ! -name "*.htm " -a ! -name "*.shtml " -a ! -name "*.db " -a ! -name "*.prn " -a ! -name "*redo* " \)'
[30]: GREPPARM=' -il'
[33]: GREPPARM=' -il -e trace'
[33]: GREPPARM=' -il -e trace -e test'
[33]: find / '\(' -type f -a ! -name '"*.so' '"' -a ! -name '"*.sl' '"' -a ! -name '"*.iso' '"' -a ! -name '"*.dbf' '"' -a ! -name '"*.tif' '"' -a ! -name '"*.dmp' '"' -a ! -name '"*.core' '"' -a ! -name '"*.html' '"' -a ! -name '"*.htm' '"' -a ! -name '"*.shtml' '"' -a ! -name '"*.db' '"' -a ! -name '"*.prn' '"' -a ! -name '"*redo*' '"' '\)' -exec grep -il -e trace -e test '{}' ';'
find: missing conjunction
Any Ideas
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2010 01:07 PM
02-02-2010 01:07 PM
Re: Shell Script problem
Hi:
This works:
#!/usr/bin/sh
FINDROOT="." #...added for testing...
FINDPARM="\( -type f "
for SUFFIX in pl txt zip #...modified for testing...
do
FINDPARM="$FINDPARM -a ! -name \"*.$SUFFIX\"" #...no trailing space...
done
for EXCLUDE in $(echo $PWDSRCH_EXCLUDE_FILE|tr -s ',' ' ')
do
FINDPARM="$FINDPARM -a ! -name \"*$EXCLUDE* \""
done
FINDPARM="$FINDPARM \)"
GREPPARM=" -il -e abort -e trace -e test" #...modified for testing...
#for STRING in $PASSWDS
#do
# GREPPARM="$GREPPARM -e $STRING"
#done
CMD="find $FINDROOT $FINDPARM -exec grep $GREPPARM {} +"
FILE=$(eval ${CMD})
for X in ${FILE}
do
echo ${X}
done
...
Regards!
...JRF...
This works:
#!/usr/bin/sh
FINDROOT="." #...added for testing...
FINDPARM="\( -type f "
for SUFFIX in pl txt zip #...modified for testing...
do
FINDPARM="$FINDPARM -a ! -name \"*.$SUFFIX\"" #...no trailing space...
done
for EXCLUDE in $(echo $PWDSRCH_EXCLUDE_FILE|tr -s ',' ' ')
do
FINDPARM="$FINDPARM -a ! -name \"*$EXCLUDE* \""
done
FINDPARM="$FINDPARM \)"
GREPPARM=" -il -e abort -e trace -e test" #...modified for testing...
#for STRING in $PASSWDS
#do
# GREPPARM="$GREPPARM -e $STRING"
#done
CMD="find $FINDROOT $FINDPARM -exec grep $GREPPARM {} +"
FILE=$(eval ${CMD})
for X in ${FILE}
do
echo ${X}
done
...
Regards!
...JRF...
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