<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: magical script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795442#M641402</link>
    <description>Tx, Laurent and Matt !!&lt;BR /&gt;Matti, your version works just fine too.&lt;BR /&gt;&lt;BR /&gt;Just one small ?:&lt;BR /&gt;&lt;BR /&gt;so those 2 lines works in the same way?&lt;BR /&gt;&lt;BR /&gt;${parameter%pattern}&lt;BR /&gt;${parameter%%pattern}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Tx&lt;BR /&gt;N</description>
    <pubDate>Sat, 04 Jun 2011 16:48:22 GMT</pubDate>
    <dc:creator>Vittorio_3</dc:creator>
    <dc:date>2011-06-04T16:48:22Z</dc:date>
    <item>
      <title>magical script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795439#M641399</link>
      <description>Hi,&lt;BR /&gt;Can anybody help me to do reverse explanation how this string was done, I tried to do my best but failed. Could not find anywhere, especially about % sign&lt;BR /&gt;&lt;BR /&gt;#  /root/bin/mar/generic_dr.ksh &lt;BR /&gt;#  becomes       generic_dr.ksh&lt;BR /&gt;&lt;BR /&gt;PGM=${0#${0%/*}/}   # !!!!!!!!!</description>
      <pubDate>Sat, 04 Jun 2011 06:29:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795439#M641399</guid>
      <dc:creator>Vittorio_3</dc:creator>
      <dc:date>2011-06-04T06:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: magical script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795440#M641400</link>
      <description>man ksh &lt;BR /&gt;  ${parameter#pattern}&lt;BR /&gt;  ${parameter##pattern} &lt;BR /&gt;If the shell pattern matches the beginning of the value of parameter, the value of this substitution is the value of the parameter with the matched portion deleted; otherwise the value of this parameter substituted.  In the former case, the smallest matching pattern is deleted; in the latter case, the largest matching pattern is deleted.&lt;BR /&gt;&lt;BR /&gt;  ${parameter%pattern}&lt;BR /&gt;  ${parameter%%pattern}&lt;BR /&gt;If the shell pattern matches the end of the value of parameter, the value of parameter with the matched part is deleted; otherwise substitute the value of parameter.  In the former, the smallest matching pattern is deleted; in the latter, the largest matching pattern is deleted.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So ${0%/*} remove the shortest  ending of the program name $0, which match with /*&lt;BR /&gt;so for instance&lt;BR /&gt;/titi/toto/tata/tutu  -&amp;gt;&lt;BR /&gt;echo ${0%/*}&lt;BR /&gt;/titi/toto/tata&lt;BR /&gt;${0#${0%/*}/}  remove the shortest from the begining matching with the previous + /&lt;BR /&gt;so&lt;BR /&gt;/titi/toto/tata/tutu   -&amp;gt; we remove /titi/toto/tata + / from the begining&lt;BR /&gt;-&amp;gt; tutu&lt;BR /&gt;&lt;BR /&gt;it is the same as $(basename $0) but without calling a coprocess.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 04 Jun 2011 07:53:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795440#M641400</guid>
      <dc:creator>Laurent Menase</dc:creator>
      <dc:date>2011-06-04T07:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: magical script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795441#M641401</link>
      <description>Wouldn't ${0##*/} accomplish the same thing in a more straightforward way?&lt;BR /&gt;&lt;BR /&gt;Or is/was there a version of ksh that had the ${parameter#pattern} and ${parameter%pattern} matches, but not the ${parameter##pattern} and ${parameter%%pattern} versions?&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Sat, 04 Jun 2011 12:14:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795441#M641401</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2011-06-04T12:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: magical script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795442#M641402</link>
      <description>Tx, Laurent and Matt !!&lt;BR /&gt;Matti, your version works just fine too.&lt;BR /&gt;&lt;BR /&gt;Just one small ?:&lt;BR /&gt;&lt;BR /&gt;so those 2 lines works in the same way?&lt;BR /&gt;&lt;BR /&gt;${parameter%pattern}&lt;BR /&gt;${parameter%%pattern}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Tx&lt;BR /&gt;N</description>
      <pubDate>Sat, 04 Jun 2011 16:48:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795442#M641402</guid>
      <dc:creator>Vittorio_3</dc:creator>
      <dc:date>2011-06-04T16:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: magical script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795443#M641403</link>
      <description>All clear now, tx all&lt;BR /&gt;</description>
      <pubDate>Sat, 04 Jun 2011 17:08:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795443#M641403</guid>
      <dc:creator>Vittorio_3</dc:creator>
      <dc:date>2011-06-04T17:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: magical script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795444#M641404</link>
      <description>&amp;gt;so those 2 lines works in the same way?&lt;BR /&gt;${parameter%pattern}&lt;BR /&gt;${parameter%%pattern}&lt;BR /&gt;&lt;BR /&gt;No.  From ksh(1): in the latter case, the largest matching pattern is deleted.</description>
      <pubDate>Sat, 04 Jun 2011 18:44:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795444#M641404</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-06-04T18:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: magical script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795445#M641405</link>
      <description>${parameter%pattern}&lt;BR /&gt;${parameter%%pattern}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;for instance &lt;BR /&gt;parameter a=/toto/titi/tata/tutu&lt;BR /&gt;echo ${a%%t*}&lt;BR /&gt;-&amp;gt; /  =&amp;gt; because the longest which matches with t* is toto/titi/tata/tutu&lt;BR /&gt;echo ${a%t*}&lt;BR /&gt;-&amp;gt; /toto/titi/tata/tu   =&amp;gt; because the shortest which matches with t* is tu&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 04 Jun 2011 19:05:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795445#M641405</guid>
      <dc:creator>Laurent Menase</dc:creator>
      <dc:date>2011-06-04T19:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: magical script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795446#M641406</link>
      <description>Removing leading directories can be done with the command basename. However, any POSIX shell will support the very simple construct mentioned above:&lt;BR /&gt; &lt;BR /&gt;MYNAME=$(basename $0)&lt;BR /&gt;or&lt;BR /&gt;MYNAME=${0##*/}&lt;BR /&gt; &lt;BR /&gt;This shell construct returns just the name of the current script. There is a companion program called dirname which returns everything except the name of the script:&lt;BR /&gt; &lt;BR /&gt;MYDIR=$(dirname $0)&lt;BR /&gt;or MYNAME=${0%/*}&lt;BR /&gt; &lt;BR /&gt;These techniques use shell built-in features which are very fast and portable. Unfortunately the man pages are not very clear and don't useful examples.&lt;BR /&gt; &lt;BR /&gt;Here's another technique:&lt;BR /&gt; &lt;BR /&gt; MYCPU=cpu1.mysite.com&lt;BR /&gt; echo ${MYCPU%%.*}&lt;BR /&gt; cpu1&lt;BR /&gt; &lt;BR /&gt;This extracts just the computer name and drops the rest of the domain name.&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Sat, 04 Jun 2011 20:32:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/magical-script/m-p/4795446#M641406</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2011-06-04T20:32:50Z</dc:date>
    </item>
  </channel>
</rss>

