<?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: what is wrong with this script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305765#M184487</link>
    <description>Now that you mention spaces, indicating a worry about detailed matching you should probably start to look at regular expression.&lt;BR /&gt;You may want to replace the whole job with some perl. For example:&lt;BR /&gt;&lt;BR /&gt; perl -ne 'if (/^\s*s\s*$/) {print "then: $_" } else {print "else: $_"}' filelist&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;perl -pe 'print (("s" eq split[0])? "then: " : "else: ")' x filelist&lt;BR /&gt;&lt;BR /&gt;This looks for a line with a single "s" and optional whitespace.&lt;BR /&gt;&lt;BR /&gt;re explanation:&lt;BR /&gt;^   = begin of line&lt;BR /&gt;\s = whitespace (space, tab)&lt;BR /&gt;\s* = zero or none whitespace&lt;BR /&gt;s  = "the real McCoy"&lt;BR /&gt;$  = end of line&lt;BR /&gt;&lt;BR /&gt;In the othere solution: split = splits default input line ($_) for words based on whitespace. The [0] selects the firs word.&lt;BR /&gt;&lt;BR /&gt;perl arguments&lt;BR /&gt;&lt;BR /&gt;-e = "script on command line"&lt;BR /&gt;-n = implied loop through STDIN, no print&lt;BR /&gt;-p = print $_ at end of implied loop itteration through STDIN&lt;BR /&gt;&lt;BR /&gt;Cheers, &lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;perl -pe 'if (/^\s*s\s*$/) {print "then: "} else {print "else: "}' filelist&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;perl -pe 'print ((/^\s*s\s*$/)? "then: " : "else: ")' filelist&lt;BR /&gt;</description>
    <pubDate>Tue, 15 Jun 2004 18:16:57 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2004-06-15T18:16:57Z</dc:date>
    <item>
      <title>what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305756#M184478</link>
      <description>#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;for xyz in `cat filelist`&lt;BR /&gt;do &lt;BR /&gt;  con=`echo $xyz`&lt;BR /&gt;  if [[ $con == "s" ]]&lt;BR /&gt;   then &lt;BR /&gt;     echo "in then"&lt;BR /&gt;   else&lt;BR /&gt;     echo "in else"&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;I don't know what is the wrong with the script,&lt;BR /&gt;the problem is the login always fall in "else" section even though con="s"?&lt;BR /&gt;&lt;BR /&gt;Please help me out. This script is running on linux serverm, but using /bin/ksh.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jun 2004 11:58:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305756#M184478</guid>
      <dc:creator>Hanry Zhou</dc:creator>
      <dc:date>2004-06-15T11:58:24Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305757#M184479</link>
      <description>Hi, &lt;BR /&gt;&lt;BR /&gt;Why do you use double brackets ?&lt;BR /&gt;&lt;BR /&gt;The right form is :&lt;BR /&gt;if [ $con=="s" ]; then&lt;BR /&gt;&lt;BR /&gt;etc.&lt;BR /&gt;&lt;BR /&gt;HTH</description>
      <pubDate>Tue, 15 Jun 2004 12:05:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305757#M184479</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2004-06-15T12:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305758#M184480</link>
      <description>First, you don't need con; simply use xyz and forget the con=`echo $xyz`&lt;BR /&gt;&lt;BR /&gt;Secondly, it's "=" not "=="&lt;BR /&gt;&lt;BR /&gt;Thirdly, protect you if's with quotes so that null variables don't kill you.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;for xyz in $(cat filelist)&lt;BR /&gt;do &lt;BR /&gt;if [[ "${xyz}" = "s" ]]&lt;BR /&gt;then &lt;BR /&gt;echo "in then"&lt;BR /&gt;else&lt;BR /&gt;echo "in else"&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jun 2004 12:06:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305758#M184480</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-06-15T12:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305759#M184481</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;== is to be replaced with =. &lt;BR /&gt;&lt;BR /&gt;It should work then.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Tue, 15 Jun 2004 12:08:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305759#M184481</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2004-06-15T12:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305760#M184482</link>
      <description>Victor,&lt;BR /&gt;&lt;BR /&gt;If I chage the way you suggested, the logic will forever fall in "then" section even though $con is not equal to "s"</description>
      <pubDate>Tue, 15 Jun 2004 12:11:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305760#M184482</guid>
      <dc:creator>Hanry Zhou</dc:creator>
      <dc:date>2004-06-15T12:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305761#M184483</link>
      <description>clay,&lt;BR /&gt;&lt;BR /&gt;the reason I use con=`echo $xyz` is because I need to run a command based on the value of $xyz, and assign the result to "con", so in my realy case, it is not con=`echo $xyz`. I just use it to replace my real command.&lt;BR /&gt;&lt;BR /&gt;2nd, if I change the way you suggested, it will forever fall in "else" section.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jun 2004 12:21:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305761#M184483</guid>
      <dc:creator>Hanry Zhou</dc:creator>
      <dc:date>2004-06-15T12:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305762#M184484</link>
      <description>If I have the string like " s", "s ", or " s ", how do I get rid of the empty strings in front or after "s"?</description>
      <pubDate>Tue, 15 Jun 2004 12:41:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305762#M184484</guid>
      <dc:creator>Hanry Zhou</dc:creator>
      <dc:date>2004-06-15T12:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305763#M184485</link>
      <description>Okay do this to strip the spaces:&lt;BR /&gt;&lt;BR /&gt;con=$(echo "${con}" | tr -d ' ')&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jun 2004 15:07:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305763#M184485</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-06-15T15:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305764#M184486</link>
      <description>Or sed&lt;BR /&gt;&lt;BR /&gt;con=$(sed "s/\ //g" $(echo $xyz))&lt;BR /&gt;&lt;BR /&gt;Tim</description>
      <pubDate>Tue, 15 Jun 2004 15:14:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305764#M184486</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2004-06-15T15:14:59Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305765#M184487</link>
      <description>Now that you mention spaces, indicating a worry about detailed matching you should probably start to look at regular expression.&lt;BR /&gt;You may want to replace the whole job with some perl. For example:&lt;BR /&gt;&lt;BR /&gt; perl -ne 'if (/^\s*s\s*$/) {print "then: $_" } else {print "else: $_"}' filelist&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;perl -pe 'print (("s" eq split[0])? "then: " : "else: ")' x filelist&lt;BR /&gt;&lt;BR /&gt;This looks for a line with a single "s" and optional whitespace.&lt;BR /&gt;&lt;BR /&gt;re explanation:&lt;BR /&gt;^   = begin of line&lt;BR /&gt;\s = whitespace (space, tab)&lt;BR /&gt;\s* = zero or none whitespace&lt;BR /&gt;s  = "the real McCoy"&lt;BR /&gt;$  = end of line&lt;BR /&gt;&lt;BR /&gt;In the othere solution: split = splits default input line ($_) for words based on whitespace. The [0] selects the firs word.&lt;BR /&gt;&lt;BR /&gt;perl arguments&lt;BR /&gt;&lt;BR /&gt;-e = "script on command line"&lt;BR /&gt;-n = implied loop through STDIN, no print&lt;BR /&gt;-p = print $_ at end of implied loop itteration through STDIN&lt;BR /&gt;&lt;BR /&gt;Cheers, &lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;perl -pe 'if (/^\s*s\s*$/) {print "then: "} else {print "else: "}' filelist&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;perl -pe 'print ((/^\s*s\s*$/)? "then: " : "else: ")' filelist&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jun 2004 18:16:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305765#M184487</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-06-15T18:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: what is wrong with this script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305766#M184488</link>
      <description>let see&lt;BR /&gt;tics for comand subsitiution are obsolete &lt;BR /&gt;echo statement is obsolete&lt;BR /&gt;== for testing of equality isn't implemented&lt;BR /&gt;&lt;BR /&gt;your script should something like&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;for xyz in $(cat filelist)&lt;BR /&gt;do &lt;BR /&gt;con=${print $xyz}&lt;BR /&gt;#although con="$xyz" does the samething only faster&lt;BR /&gt;&lt;BR /&gt;if [[ "$con" = "s" ]]&lt;BR /&gt;then &lt;BR /&gt;print "in then"&lt;BR /&gt;else&lt;BR /&gt;print "in else"&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;and for removeing characters&lt;BR /&gt;print "$xyz" | tr -cd "[:alnum:]"&lt;BR /&gt;which will delete all characters that aren't alphanumeric&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jun 2004 20:34:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/what-is-wrong-with-this-script/m-p/3305766#M184488</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2004-06-15T20:34:51Z</dc:date>
    </item>
  </channel>
</rss>

