[SunHELP] dirname command pipe failure

Sandwich Maker adh at an.bradford.ma.us
Thu Jun 24 10:22:44 CDT 2004


" From: "Jopson, Andy" <Andrew.Jopson at Rolls-Royce.com>
" 
" Does anybody know why I can't write the following code as a pipe?
" 
" 	temp=`echo $1 | tr '.' '/'`
" 	temp=`dirname $temp`
" 	echo $temp | tr '/' '.'
" 
" Like this:  echo $1 | tr '.' '/'` | dirname | tr '/' '.'
" 
" It just returns a . rather than the body of a filename (I wrote the code to
" get whatever comes before the final dot in a filename i.e. it separates the
" filename from it's extension). It appears that dirname (or basename for that
" matter) doesn't function in a pipe command.

simplest answer:  use ksh.

echo ${1%.*}
does it right off.  if you want the extension alone,
echo ${1##*.}
instead.

i use ${0##*/} all the time in shell scripts to get the script name.

and could you please trim all the redundant rubbish from the tail of
your replies?  your last answer was over 200 lines!  most of which
were sig after sig after sig...
________________________________________________________________________
Andrew Hay                                  the genius nature
internet rambler                            is to see what all have seen
adh at an.bradford.ma.us                       and think what none thought



More information about the SunHELP mailing list