<?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 bash script array in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239401#M73758</link>
    <description>Hello all.&lt;BR /&gt;&lt;BR /&gt;I need help for bash script.&lt;BR /&gt;&lt;BR /&gt;I want to write script like this...&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;EE[0]="foo is FOO"&lt;BR /&gt;EE[1]="bars are BAR BAR BAR"&lt;BR /&gt;EE[2]=...&lt;BR /&gt;EE[3]=...&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;if grep -e ${EE[0]} -e ${EE[1]} -e ${EE[2]} .... file&lt;BR /&gt;then&lt;BR /&gt;    foo...&lt;BR /&gt;fi&lt;BR /&gt;---&lt;BR /&gt;&lt;BR /&gt;How do I write "grep..."?&lt;BR /&gt;EE array size is not fixed.&lt;BR /&gt;&lt;BR /&gt;e.g.) GREP_OPT=${EE[@]://-e/}... this don't work well....&lt;BR /&gt;&lt;BR /&gt;I hope smart script.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
    <pubDate>Mon, 05 Apr 2004 01:54:17 GMT</pubDate>
    <dc:creator>Kiyoshi Miyake</dc:creator>
    <dc:date>2004-04-05T01:54:17Z</dc:date>
    <item>
      <title>bash script array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239401#M73758</link>
      <description>Hello all.&lt;BR /&gt;&lt;BR /&gt;I need help for bash script.&lt;BR /&gt;&lt;BR /&gt;I want to write script like this...&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;EE[0]="foo is FOO"&lt;BR /&gt;EE[1]="bars are BAR BAR BAR"&lt;BR /&gt;EE[2]=...&lt;BR /&gt;EE[3]=...&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;if grep -e ${EE[0]} -e ${EE[1]} -e ${EE[2]} .... file&lt;BR /&gt;then&lt;BR /&gt;    foo...&lt;BR /&gt;fi&lt;BR /&gt;---&lt;BR /&gt;&lt;BR /&gt;How do I write "grep..."?&lt;BR /&gt;EE array size is not fixed.&lt;BR /&gt;&lt;BR /&gt;e.g.) GREP_OPT=${EE[@]://-e/}... this don't work well....&lt;BR /&gt;&lt;BR /&gt;I hope smart script.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Mon, 05 Apr 2004 01:54:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239401#M73758</guid>
      <dc:creator>Kiyoshi Miyake</dc:creator>
      <dc:date>2004-04-05T01:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: bash script array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239402#M73759</link>
      <description>So basically you want to fill an array with patterns, then do a multi-pattern-grep with all the listed patterns?&lt;BR /&gt;&lt;BR /&gt;Ok, that's not too hard.&lt;BR /&gt;&lt;BR /&gt;Unfortunately you can't do a:&lt;BR /&gt;&lt;BR /&gt;grep -e ${EE[@]/#/ -e }&lt;BR /&gt;&lt;BR /&gt;As it treats the entire ${} as a single string/pattern.  You need to build up your command line with a simple loop:&lt;BR /&gt;&lt;BR /&gt;for ARG in ${EE[@]}&lt;BR /&gt;do&lt;BR /&gt;  MY_ARG="-e $ARG $MY_ARG"&lt;BR /&gt;done&lt;BR /&gt;grep $MY_ARG file&lt;BR /&gt;&lt;BR /&gt;Give it a shot, see how it does for you.</description>
      <pubDate>Mon, 05 Apr 2004 02:14:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239402#M73759</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2004-04-05T02:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: bash script array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239403#M73760</link>
      <description>If you have a lot of patterns, maybe a pattern file would be simpler ;&lt;BR /&gt;uglier but easier to debug.&lt;BR /&gt;&lt;BR /&gt;Perl is also great for pattern matching/replacing, and you'll have the case insensitive option :&lt;BR /&gt;perl -pe ' s/pattern1/replacement1/g ; s/pattern1/replacement1/iog ' filename&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Apr 2004 02:39:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239403#M73760</guid>
      <dc:creator>Nicolas Dumeige</dc:creator>
      <dc:date>2004-04-05T02:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: bash script array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239404#M73761</link>
      <description>Thank you for quick reply.&lt;BR /&gt;&lt;BR /&gt;But, I need more help.&lt;BR /&gt;&lt;BR /&gt;----&lt;BR /&gt;EE[0]="foo is FOO"&lt;BR /&gt;EE[1]="bars are BAR BAR BAR"&lt;BR /&gt;&lt;BR /&gt;for ARG in ${EE[@]}&lt;BR /&gt;do&lt;BR /&gt;MY_ARG="-e $ARG $MY_ARG"&lt;BR /&gt;done&lt;BR /&gt;echo "$MY_ARG"&lt;BR /&gt;----&lt;BR /&gt;result of this script is:&lt;BR /&gt;---&lt;BR /&gt;-e BAR -e BAR -e BAR -e are -e bars -e FOO -e is -e foo&lt;BR /&gt;---&lt;BR /&gt;&lt;BR /&gt;I need :&lt;BR /&gt;-e "foo is FOO" -e "bars are BAR BAR BAR"&lt;BR /&gt;&lt;BR /&gt;EE[] is phrase.&lt;BR /&gt;What do I write?&lt;BR /&gt;&lt;BR /&gt;thanks.&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Apr 2004 03:19:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239404#M73761</guid>
      <dc:creator>Kiyoshi Miyake</dc:creator>
      <dc:date>2004-04-05T03:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: bash script array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239405#M73762</link>
      <description>Try this :&lt;BR /&gt;&lt;BR /&gt;EE[0]="foo is FOO"&lt;BR /&gt;EE[1]="bars are BAR BAR BAR"&lt;BR /&gt;&lt;BR /&gt;cpt=0&lt;BR /&gt;while [ cpt -lt ${#EE[@]} ]&lt;BR /&gt;do&lt;BR /&gt;        MY_ARG="-e '${EE[cpt]}'  $MY_ARG"&lt;BR /&gt;        (( cpt += 1 ))&lt;BR /&gt;done&lt;BR /&gt;echo "$MY_ARG"&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Apr 2004 04:43:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239405#M73762</guid>
      <dc:creator>Nicolas Dumeige</dc:creator>
      <dc:date>2004-04-05T04:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: bash script array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239406#M73763</link>
      <description>Thanks Nicolas.&lt;BR /&gt;&lt;BR /&gt;grep "$MY_ARG" ... don't work well.&lt;BR /&gt;but eval "$MY_ARG" (add grep) work well.&lt;BR /&gt;&lt;BR /&gt;$ cat foo.sh&lt;BR /&gt;EE[0]="foo is FOO"&lt;BR /&gt;EE[1]="bars are BAR BAR BAR"&lt;BR /&gt;&lt;BR /&gt;MY_ARG="grep -v "&lt;BR /&gt;cpt=0&lt;BR /&gt;while [ $cpt -lt ${#EE[@]} ]&lt;BR /&gt;do&lt;BR /&gt;MY_ARG="$MY_ARG -e '${EE[cpt]}'"&lt;BR /&gt;(( cpt += 1 ))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;MY_ARG="$MY_ARG foo.sh"&lt;BR /&gt;echo $MY_ARG&lt;BR /&gt;eval $MY_ARG&lt;BR /&gt;$ sh foo.sh&lt;BR /&gt;grep -v -e 'foo is FOO' -e 'bars are BAR BAR BAR' foo.sh&lt;BR /&gt;&lt;BR /&gt;MY_ARG="grep -v "&lt;BR /&gt;cpt=0&lt;BR /&gt;while [ $cpt -lt ${#EE[@]} ]&lt;BR /&gt;do&lt;BR /&gt;MY_ARG="$MY_ARG -e '${EE[cpt]}'"&lt;BR /&gt;(( cpt += 1 ))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;MY_ARG="$MY_ARG foo.sh"&lt;BR /&gt;echo $MY_ARG&lt;BR /&gt;eval $MY_ARG&lt;BR /&gt;$&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# but. script become long...&lt;BR /&gt;&lt;BR /&gt;Thanks a lot.&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Apr 2004 05:04:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239406#M73763</guid>
      <dc:creator>Kiyoshi Miyake</dc:creator>
      <dc:date>2004-04-05T05:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: bash script array</title>
      <link>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239407#M73764</link>
      <description>Hi,&lt;BR /&gt;if you don't want to use an array you can try this one:&lt;BR /&gt;&lt;BR /&gt;MY_ARG=`(cat &amp;lt;&amp;lt; EOF&lt;BR /&gt;foo is FOO&lt;BR /&gt;bar are BAR BAR BAR&lt;BR /&gt;more things&lt;BR /&gt;EOF&lt;BR /&gt;) | awk '{printf("grep -e \"%s\"\n",$0)}'`&lt;BR /&gt;&lt;BR /&gt;echo $MY_ARG&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Be careful with the quotation, cut and paste if you don't want errors.&lt;BR /&gt;&lt;BR /&gt;Frank.</description>
      <pubDate>Mon, 05 Apr 2004 05:20:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/bash-script-array/m-p/3239407#M73764</guid>
      <dc:creator>Francisco J. Soler</dc:creator>
      <dc:date>2004-04-05T05:20:57Z</dc:date>
    </item>
  </channel>
</rss>

