Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
It would help if you explain what you expect this command to achieve, especially the $0 and PARSEDATA stuff. – jlliagre Apr 12 '11 at 9:23
@jlliagre, Clear enough? – user32178 Apr 12 '11 at 9:28
Yes, thanks. Have a look at my reply. – jlliagre Apr 12 '11 at 16:10

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 {}


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
share|improve this answer
Have you checked so sh is simply not a symlink towards bash and that you're not using a GNU find? – user32178 Apr 12 '11 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 '11 at 9:54
Oh, just by curiosity : what does my example do on your pure sh? – M'vy Apr 12 '11 at 10:16
It's because there must be a /bin/sh binary that is compatible with Bourne shell. – grawity Apr 12 '11 at 13:11

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

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

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.