<?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: How to pass a list from the command line in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177331#M50806</link>
    <description>Hi Dennis&lt;BR /&gt;&lt;BR /&gt;In fact I'd like to replace &amp;lt; /home/test/bin/oas_replication_cde.txt by the command given in the command line like this:&lt;BR /&gt;&lt;BR /&gt;./myscript.ksh "ls -lrt" a1001 b1002 c1004 ....&lt;BR /&gt;&lt;BR /&gt;I've try this:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;USER=applopus&lt;BR /&gt;echo "servers: $*" # all parameters in one&lt;BR /&gt;&lt;BR /&gt;if [ "$1" = "" ]; then&lt;BR /&gt;    echo "ERROR: no servers listed!"&lt;BR /&gt;    exit 99&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;echo "Command is: "$1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;while [ "$2" != "" ]&lt;BR /&gt;do&lt;BR /&gt;    echo "\n$2" &amp;gt;&amp;gt; $OUTPUT&lt;BR /&gt;    sftp $USER@$i &amp;lt; $1&lt;BR /&gt;    shift&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But of course the syntaxe is not correct. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Any Idea ?&lt;BR /&gt;&lt;BR /&gt;Best Regards&lt;BR /&gt;Den&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 26 May 2009 11:42:13 GMT</pubDate>
    <dc:creator>Leo The Cat</dc:creator>
    <dc:date>2009-05-26T11:42:13Z</dc:date>
    <item>
      <title>How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177327#M50802</link>
      <description>Hi &lt;BR /&gt;&lt;BR /&gt;I need to call my script like this:&lt;BR /&gt;&lt;BR /&gt;./myscript.ksh a1001 b1002 c1004 ....&lt;BR /&gt;&lt;BR /&gt;AND&lt;BR /&gt;&lt;BR /&gt;I have to list this with a loop (fow or while). I've tried somethink like that but of course, this does not work. &lt;BR /&gt;&lt;BR /&gt;....&lt;BR /&gt;servers=$1&lt;BR /&gt;echo "servers: " $servers&lt;BR /&gt;USER=test&lt;BR /&gt;for i in (`$servers`)&lt;BR /&gt;do&lt;BR /&gt;echo "\n$i" &amp;gt;&amp;gt; $OUTPUT&lt;BR /&gt;&lt;BR /&gt;sftp $USER@$i &amp;lt; /home/test/bin/oas_replication_cde.txt&lt;BR /&gt;done&lt;BR /&gt;......&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;How to do this ?&lt;BR /&gt;&lt;BR /&gt;Thanks a lot&lt;BR /&gt;Regards&lt;BR /&gt;Den</description>
      <pubDate>Mon, 25 May 2009 17:36:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177327#M50802</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-05-25T17:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177328#M50803</link>
      <description>&lt;!--!*#--&gt;When you call a script like this:&lt;BR /&gt;&lt;BR /&gt;./myscript.ksh a1001 b1002 c1004 ...&lt;BR /&gt;&lt;BR /&gt;the parameters are assigned like this:&lt;BR /&gt;&lt;BR /&gt;$1 = a1001&lt;BR /&gt;$2 = b1002&lt;BR /&gt;$3 = c1004&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;The simplest way to handle this is to use the "shift" command. It moves the parameters so that $2 becomes $1, $3 becomes $2, etc. The old $1 is discarded.&lt;BR /&gt;&lt;BR /&gt;So we can make each parameter in turn be $1 in our loop, and use only $1 for anything we need a parameter for. When $1 becomes empty, we know have processed all the parameters.&lt;BR /&gt;&lt;BR /&gt;USER=test&lt;BR /&gt;echo "servers: $*" # all parameters in one&lt;BR /&gt;&lt;BR /&gt;if [ "$1" = "" ]; then&lt;BR /&gt;    echo "ERROR: no servers listed!"&lt;BR /&gt;    exit 99&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;while [ "$1" != "" ]&lt;BR /&gt;do&lt;BR /&gt;    echo "\n$1" &amp;gt;&amp;gt; $OUTPUT&lt;BR /&gt;    sftp $USER@$1 &amp;lt; /home/test/bin/oas_replication_cde.txt&lt;BR /&gt;    shift&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;MK</description>
      <pubDate>Mon, 25 May 2009 18:03:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177328#M50803</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2009-05-25T18:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177329#M50804</link>
      <description>Huh&lt;BR /&gt;&lt;BR /&gt;I had closed in a first time this thread but i have an ultimate question . &lt;BR /&gt;&lt;BR /&gt;How to bypass the file oas_replication_cde.txt&lt;BR /&gt;&lt;BR /&gt;That mean going with a full command line without any config or command file&lt;BR /&gt;&lt;BR /&gt;I think this is not possible because how to distinguish command and servers in the parameters ....&lt;BR /&gt;&lt;BR /&gt;Is this (something like that) possible&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;./myscript.ksh   "ls -lrt /tmp" a1001 b1002 c1004&lt;BR /&gt;&lt;BR /&gt;Wher i know that "..." ismy first parameter "!&lt;BR /&gt;&lt;BR /&gt;Bests Regards&lt;BR /&gt;Den&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 25 May 2009 19:26:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177329#M50804</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-05-25T19:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177330#M50805</link>
      <description>As Matti said, the standard way to crack the command line is with shift.  You can also put them in an array, if no more than 1023:&lt;BR /&gt;set -A array_var -- "${@}"&lt;BR /&gt;&lt;BR /&gt;&amp;gt;How to bypass the file oas_replication_cde.txt&lt;BR /&gt;&lt;BR /&gt;What do you mean?  You want to exclude that special file if on the command line?&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I think this is not possible because how to distinguish command and servers in the parameters ...&lt;BR /&gt;&lt;BR /&gt;You need to put a special delimiter there or a - option.  Or have a fixed count.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Is this possible&lt;BR /&gt;./myscript.ksh "ls -lrt /tmp" a1001 b1002 c1004&lt;BR /&gt;&lt;BR /&gt;Sure.  The first parm is "ls -lrt /tmp".&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Where I know that "..." is my first parameter!&lt;BR /&gt;&lt;BR /&gt;You mean starting with $2?&lt;BR /&gt;&lt;BR /&gt;&amp;gt;Matti: When $1 becomes empty, we know have processed all the parameters.&lt;BR /&gt;&amp;gt;if [ "$1" = "" ]; then&lt;BR /&gt;&amp;gt;while [ "$1" != "" ]; do&lt;BR /&gt;&lt;BR /&gt;The proper test is to check the count of parms, not their value.  You can have empty parms.&lt;BR /&gt;&lt;BR /&gt;if [ $# -gt 0 ]; then&lt;BR /&gt;while [ $# -gt 0 ]; do</description>
      <pubDate>Tue, 26 May 2009 01:29:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177330#M50805</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-05-26T01:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177331#M50806</link>
      <description>Hi Dennis&lt;BR /&gt;&lt;BR /&gt;In fact I'd like to replace &amp;lt; /home/test/bin/oas_replication_cde.txt by the command given in the command line like this:&lt;BR /&gt;&lt;BR /&gt;./myscript.ksh "ls -lrt" a1001 b1002 c1004 ....&lt;BR /&gt;&lt;BR /&gt;I've try this:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;USER=applopus&lt;BR /&gt;echo "servers: $*" # all parameters in one&lt;BR /&gt;&lt;BR /&gt;if [ "$1" = "" ]; then&lt;BR /&gt;    echo "ERROR: no servers listed!"&lt;BR /&gt;    exit 99&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;echo "Command is: "$1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;while [ "$2" != "" ]&lt;BR /&gt;do&lt;BR /&gt;    echo "\n$2" &amp;gt;&amp;gt; $OUTPUT&lt;BR /&gt;    sftp $USER@$i &amp;lt; $1&lt;BR /&gt;    shift&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;But of course the syntaxe is not correct. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Any Idea ?&lt;BR /&gt;&lt;BR /&gt;Best Regards&lt;BR /&gt;Den&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 26 May 2009 11:42:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177331#M50806</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-05-26T11:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177332#M50807</link>
      <description>I've try this but not correct&lt;BR /&gt;&lt;BR /&gt;USER=applopus&lt;BR /&gt;echo "servers: $*" # all parameters in one&lt;BR /&gt;&lt;BR /&gt;if [ "$1" = "" ]; then&lt;BR /&gt;    echo "ERROR: no servers listed!"&lt;BR /&gt;    exit 99&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;echo "Command is: "$1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;while [ "$2" != "" ]&lt;BR /&gt;do&lt;BR /&gt;    echo "\n$2" &amp;gt;&amp;gt; $OUTPUT&lt;BR /&gt;&lt;BR /&gt;    sftp  $USER@$2 &amp;lt;&amp;lt; "EOF"&lt;BR /&gt;    ls&lt;BR /&gt;    quit&lt;BR /&gt;    EOF  &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;    shift&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Tue, 26 May 2009 12:30:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177332#M50807</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-05-26T12:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177333#M50808</link>
      <description>&lt;!--!*#--&gt;Hi Den:&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;OUTPUT=/dev/tty&lt;BR /&gt;USER=applopus&lt;BR /&gt;echo "servers: $*" # all parameters in one&lt;BR /&gt;if [ -z "$1" ]; then&lt;BR /&gt;    echo "ERROR: no servers listed!"&lt;BR /&gt;    exit 99&lt;BR /&gt;fi&lt;BR /&gt;CMD=$1&lt;BR /&gt;shift&lt;BR /&gt;echo "Command is: ${CMD}"&lt;BR /&gt;while [ ! -z "$1" ]&lt;BR /&gt;do&lt;BR /&gt;    echo "\n$1" &amp;gt;&amp;gt; $OUTPUT&lt;BR /&gt;    echo "sftp $USER@$1 &amp;lt; ${CMD}"&lt;BR /&gt;    shift&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 26 May 2009 12:37:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177333#M50808</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-05-26T12:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177334#M50809</link>
      <description>Hi James&lt;BR /&gt;&lt;BR /&gt;Doesnt work. In fact sftp needs the &amp;lt; with a file. It's curious, but finally I've decided to go with a temporary file (Avoid this should nicest but not so bad) with code like this. &lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;echo $1 &amp;gt; /tmp/oas_replication.$$$&lt;BR /&gt;&lt;BR /&gt;while [ "$2" != "" ]&lt;BR /&gt;do&lt;BR /&gt;    sftp $USER@$2 &amp;lt; /tmp/oas_replication.$$$&lt;BR /&gt;    shift&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;rm -f /tmp/oas_replication.$$$&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for all your answers. I've learn again many things by this thread.&lt;BR /&gt;Bests Regards&lt;BR /&gt;Den</description>
      <pubDate>Tue, 26 May 2009 13:44:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177334#M50809</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-05-26T13:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177335#M50810</link>
      <description>Not solved without a temporary file. &lt;BR /&gt;&lt;BR /&gt;Thanks All&lt;BR /&gt;Bests Regards&lt;BR /&gt;Den</description>
      <pubDate>Tue, 26 May 2009 13:46:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177335#M50810</guid>
      <dc:creator>Leo The Cat</dc:creator>
      <dc:date>2009-05-26T13:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass a list from the command line</title>
      <link>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177336#M50811</link>
      <description>&amp;gt;In fact I'd like to replace &amp;lt; .../oas_replication_cde.txt by the command given in the command line like this:&lt;BR /&gt;./myscript.ksh "ls -lrt" a1001 b1002 c1004 ....&lt;BR /&gt; sftp $USER@$i &amp;lt; $1&lt;BR /&gt;&lt;BR /&gt;You want to echo the command or the output of that command?&lt;BR /&gt;You use a pipe:&lt;BR /&gt;CMD=$1&lt;BR /&gt;...&lt;BR /&gt;echo "$CMD" | sftp $USER@$i&lt;BR /&gt;&lt;BR /&gt;&amp;gt;In fact sftp needs the &amp;lt; with a file.&lt;BR /&gt;&lt;BR /&gt;A pipe should work the same.</description>
      <pubDate>Sat, 30 May 2009 14:10:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/how-to-pass-a-list-from-the-command-line/m-p/5177336#M50811</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-05-30T14:10:30Z</dc:date>
    </item>
  </channel>
</rss>

