tag:blogger.com,1999:blog-4292105858544147974.post8243485638750499395..comments2023-03-31T08:10:41.725-07:00Comments on Useful functions and commands: ps2pdf to all ps files in current directoryHakyhttp://www.blogger.com/profile/10013572452231003502noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-4292105858544147974.post-7296273759297198192012-02-03T09:18:06.120-08:002012-02-03T09:18:06.120-08:00Haky -
This is a little too complicated:
for x in...Haky -<br /><br />This is a little too complicated:<br />for x in $(ls *.ps); do echo $x; ps2pdf $x $(echo $x|sed -e 's/ps$/pdf/');done<br /><br />The key is to speak with no unnecessary words:<br /><br />Every $(...) expression runs a new bash shell as a child - both are unnecessary.<br /><br />ls *.ps - runs a program with the shell expanding wildcard names to a list of matching names; for you the directory-listing program serves no purpose;<br /><br />The second parenthesized expression used to form the output file-name is launching the powerful sed program to do the simplest of substitutions.<br /><br />The simple substitution you need can be readily done by the shell (bash, these days, if you're either on mac or linux).<br /><br />Here's the simpler, faster, easier to read, more direct version:<br /><br />for x in *.ps; do<br /> echo $x;<br /> ps2pdf $x ${x/%ps/pdf};<br />done<br /><br />Search for the section on "Parameter Expansion" in the bash man page (man bash) for details about substitution syntax.Yarkohttps://www.blogger.com/profile/17636888748650027415noreply@blogger.com