1

I have this command that I'm trying to execute in the bourne shell for Solaris 9.

find ${DATADIR} -name "check_*" -type f -exec sh -c '$0 | ${PARSEDATA}' {} \; >> ${TMP_1}

My problem is, the variable ${PARSEDATA} won't work properly, I have tried using double quotes around it, then the problem is $0 is the name of the script executing this code, not the file located using the find command.

Any suggestions to solve this, probably easy problem, is greatly helpful.

Thanks in advance.

Update: $0 is the name of the script located using the find command, the variable for ${PARSEDATA} is a filter, located somewhere on the system that modifies the output of each located script. However, the problem is, I can't seem to get both $0 and ${PARSEDATA} to expand properly, either $0 expands fine using single quotes, or using double qoutes ${PARSEDATA} expands fine, but then $0 becomes the name of the orginal script that runs this find-command.

2
  • It would help if you explain what you expect this command to achieve, especially the $0 and PARSEDATA stuff.
    – jlliagre
    Apr 12, 2011 at 9:23
  • @jlliagre, Clear enough?
    – user32178
    Apr 12, 2011 at 9:28

3 Answers 3

0

I'm not sure of what you are trying to do? But if you want to look for scripts named check_* and then run it and pipe it through a program ${PARSE_DATA}, well I guess the file located by find is not $0 but {}

Example

find /var/ftp/mp3 -name "*.mp3" -type f -exec chmod 644 {} \; (Wikipedia)

So I think you can use your double quotes :

find ${DATADIR} -name "check_*" -type f -exec sh -c '{} | ${PARSEDATA}' \; >> ${TMP_1}

I've tried successfully :

PG='sed s/Blah/Bleh/'
find . -name "check_*" -type f -exec sh -c "{} | $PG" \;

> Bleh Blah
4
  • Have you checked so sh is simply not a symlink towards bash and that you're not using a GNU find?
    – user32178
    Apr 12, 2011 at 9:39
  • Hummmm in fact, it's a symlink to /bin/dash... what is the point of calling it sh then. Damn it. But seems to be GNU find by the way.
    – M'vy
    Apr 12, 2011 at 9:54
  • Oh, just by curiosity : what does my example do on your pure sh?
    – M'vy
    Apr 12, 2011 at 10:16
  • It's because there must be a /bin/sh binary that is compatible with Bourne shell. Apr 12, 2011 at 13:11
0

Keep the single quotes, the issue is very likely you haven't exported the PARSEDATA variable.

export PARSEDATA
find ${DATADIR} -name "check_*" -type f -exec sh -c '$0 | ${PARSEDATA}' {} \; >> ${TMP_1}
0

If you want $0 to not be expanded by the shell (using single quotes) and ${PARSEDATA} be expanded, then why not just use different quotes for each:

find ${DATADIR} -name "check_*" -type f -exec sh -c '$0 | '"${PARSEDATA}" {} \; >> ${TMP_1}

As long as you keep the quoted parts joined, the shell will just expand ${PARSEDATA} and pass the whole command as a single token to find.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .