<?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: Script help! in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019477#M428201</link>
    <description>You are missing "do"&lt;BR /&gt;&lt;BR /&gt;for user in .....&lt;BR /&gt;do &lt;BR /&gt;  .....&lt;BR /&gt;  .....&lt;BR /&gt;done&lt;BR /&gt;</description>
    <pubDate>Mon, 18 Dec 2006 19:46:48 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2006-12-18T19:46:48Z</dc:date>
    <item>
      <title>Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019476#M428200</link>
      <description>Hello all,&lt;BR /&gt;Please hekp me to correct this script.&lt;BR /&gt;&lt;BR /&gt;this script will read the file "test_userlist" and create users with 2 comments&lt;BR /&gt;But i always receive error below.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh -x&lt;BR /&gt;for user in `cat test_userlist`&lt;BR /&gt;NAME=`echo $user | awk -F\: '{print $1}'`&lt;BR /&gt;FULLNAME=`echo $user | awk -F\: '{print $2}'`&lt;BR /&gt;COUNTRY=`echo $user | awk -F\: '{print $3}'`&lt;BR /&gt;do useradd -m -s /usr/bin/false -g sunml   -c "${FULLNAME},${COUNTRY}" $NAME&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;the content of file "test_userlist"&lt;BR /&gt;&lt;BR /&gt;sally00:test00:australia&lt;BR /&gt;sally01:test01:australia&lt;BR /&gt;sally02:test02:australia&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;received this error when ran it&lt;BR /&gt;&lt;BR /&gt;./cr_user.sh.t[2]: Syntax error at line 4 : `NAME=`echo $user | awk -F: '{print $1}'`' is not expected.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;thanks in advance.&lt;BR /&gt;Tom</description>
      <pubDate>Mon, 18 Dec 2006 19:31:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019476#M428200</guid>
      <dc:creator>tom quach_1</dc:creator>
      <dc:date>2006-12-18T19:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019477#M428201</link>
      <description>You are missing "do"&lt;BR /&gt;&lt;BR /&gt;for user in .....&lt;BR /&gt;do &lt;BR /&gt;  .....&lt;BR /&gt;  .....&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Dec 2006 19:46:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019477#M428201</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-12-18T19:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019478#M428202</link>
      <description>&lt;!--!*#--&gt;And just to make things much easier to read, everyone should really NOT use the back-ticks (`).&lt;BR /&gt;&lt;BR /&gt;The new way to do this is with the $(statement) syntax.  &lt;BR /&gt;&lt;BR /&gt;Your script for example:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh -x&lt;BR /&gt;for user in $(cat test_userlist)&lt;BR /&gt;do&lt;BR /&gt;   NAME=$(echo $user | awk -F\: '{print $1}')&lt;BR /&gt;   FULLNAME=$(echo $user | awk -F\: '{print $2}')&lt;BR /&gt;   COUNTRY=$(echo $user | awk -F\: '{print $3}')&lt;BR /&gt;   useradd -m -s /usr/bin/false -g sunml -c "${FULLNAME},${COUNTRY}" $NAME&lt;BR /&gt;&lt;BR /&gt;done</description>
      <pubDate>Mon, 18 Dec 2006 19:51:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019478#M428202</guid>
      <dc:creator>Patrick Wallek</dc:creator>
      <dc:date>2006-12-18T19:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019479#M428203</link>
      <description>Hi Tom:&lt;BR /&gt;&lt;BR /&gt;The use of 'cat' adds another process that isn't needed.  In fact, you can do away with 'awk' and use the shell to split your line into component fields:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;OLDIFS=${IFS}&lt;BR /&gt;IFS=":"&lt;BR /&gt;while read NAME FULLNAME COUNTRY X&lt;BR /&gt;do&lt;BR /&gt;    useradd -m -s /usr/bin/false -g sunml -c "${FULLNAME},${COUNTRY}" $NAME&lt;BR /&gt;done &amp;lt; test_userlist&lt;BR /&gt;IFS=${OLDIFS}&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 18 Dec 2006 20:07:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019479#M428203</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-18T20:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019480#M428204</link>
      <description>Thank you all for your prompt response.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Tom</description>
      <pubDate>Mon, 18 Dec 2006 20:29:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019480#M428204</guid>
      <dc:creator>tom quach_1</dc:creator>
      <dc:date>2006-12-18T20:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019481#M428205</link>
      <description>FWIW, &lt;BR /&gt;the "cut" command, when it can be used is much faster than firing up awk for each line.&lt;BR /&gt;&lt;BR /&gt;--- cut example ---&lt;BR /&gt;for user in `cat test_userlist`&lt;BR /&gt;do&lt;BR /&gt;NAME=`echo $user | cut -f1 -d:`&lt;BR /&gt;FULLNAME=`echo $user | cut -f2 -d:`&lt;BR /&gt;COUNTRY=`echo $user | cut -f3 -d:`&lt;BR /&gt;useradd -m -s /usr/bin/false -g sunml -c "${FULLNAME},${COUNTRY}" $NAME&lt;BR /&gt;done&lt;BR /&gt;----- end of cut example ---&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;BUT, you could get this done in fewer lines using the "set" command:&lt;BR /&gt;&lt;BR /&gt;----- set example -------&lt;BR /&gt;for user in `cat test_userlist`&lt;BR /&gt;do&lt;BR /&gt;set `echo $user | sed "s/:/ /g"`&lt;BR /&gt;useradd -m -s /usr/bin/false -g sunml -c       "${2},${3}" $1&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;---- end of set example ----&lt;BR /&gt;&lt;BR /&gt;What the example above is doing is using sed to put spaces between the words so that the shell command "set" would be able to parse the contents of $user into $1, $2 and $3.  Then of course those arguments used as would you have with the variables you used for the useradd command ... it's just less readable - as is it seems most things which can be done "quicker" in the shell are.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 18 Dec 2006 20:30:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019481#M428205</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2006-12-18T20:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019482#M428206</link>
      <description>&lt;!--!*#--&gt;Wow, ... robbed by 1 MINUTE 1!!&lt;BR /&gt;&lt;BR /&gt;:-) :-) :-)</description>
      <pubDate>Mon, 18 Dec 2006 20:31:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019482#M428206</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2006-12-18T20:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019483#M428207</link>
      <description>&lt;!--!*#--&gt;In regards to JRF's comment about an silly use of cat in Tom's improvements:&lt;BR /&gt;    for user in $(cat test_userlist)&lt;BR /&gt;to: for user in $(&amp;lt; test_userlist)&lt;BR /&gt;&lt;BR /&gt;It seems that Clay was not quite right in the original case.  The "do" is there but it is on the wrong line and there is a bunch of missing "`".&lt;BR /&gt;&lt;BR /&gt;In regards to John's comment about cut vs awk, I've found that cut has an interface that is just too complex to understand.  awk is simple and doesn't have a problem with "field delimiters delimit null fields".</description>
      <pubDate>Mon, 18 Dec 2006 22:13:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019483#M428207</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2006-12-18T22:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019484#M428208</link>
      <description>Dennis,&lt;BR /&gt;&lt;BR /&gt;you're right, cut is a bit funkier especially when the delimiters are not a single character: that's why I added "when it can be used".&lt;BR /&gt;&lt;BR /&gt;I use awk when the parse is more complex, but when it a simple reliable single character - I'll grab the "cut" command as it really does run much faster, especially when one is looking to parse a large number of lines (like thousands).  But, I don't get to use it as often, because data these days don't seem to be laid out as rigourosly in printed record form like in the old IBM mainframe and /or old Fortran days (not that I'm getting wistful for going back to that stuff again).&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Dec 2006 10:51:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019484#M428208</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2006-12-19T10:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Script help!</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019485#M428209</link>
      <description>Thanks Dennis &lt;BR /&gt;&lt;BR /&gt;never use this "," before&lt;BR /&gt;to: for user in $(&amp;lt; test_userlist)&lt;BR /&gt;&lt;BR /&gt;just learn something new.&lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;BR /&gt;Tom</description>
      <pubDate>Tue, 19 Dec 2006 13:36:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-help/m-p/5019485#M428209</guid>
      <dc:creator>tom quach_1</dc:creator>
      <dc:date>2006-12-19T13:36:11Z</dc:date>
    </item>
  </channel>
</rss>

