Release Automation

Expand all | Collapse all

Execute shell script with prompt for input

Jump to Best Answer
  • 1.  Execute shell script with prompt for input

    Posted 04-13-2017 01:02 AM

    Good night,

     

    I have a question about automating the execution of a shell script that prompts the user for parameters. Usually for shells I would use the action [run command line], but I'm not sure how to use it when the shell I want to execute does something like this :

     

    $ ./buildAPP.sh

     

    and then I get the following menu :

     

    Choose the task you want to perform :
    [1] Deploy APP initially
    [2] Deploy APP incrementally
    [3] Exit

     

    how can I model this in RA?



  • 2.  Re: Execute shell script with prompt for input

    Posted 04-13-2017 03:03 AM

    Hi

    Did you check this thread?

    Tech Tip:How to run interactive command line 

     

    Thanks

    Jacky 



  • 3.  Re: Execute shell script with prompt for input

    Posted 04-17-2017 11:45 AM

    Hello Jacky,

     

    Thanks for the answer. To clarify : so it would be correct to do something like this? : 

     

    1 . User input action to get parameter_A

    2. User input action to get parameter_B

    3. Run command line using echo with parameter_A and parameter_B



  • 4.  Re: Execute shell script with prompt for input
    Best Answer

    Broadcom Employee
    Posted 04-17-2017 01:37 PM

    Hi Julio,

     

    Someone here might know of a syntax that will get you the result you're looking for. If not then it might mean that you need to modify the script slightly to assign the variables to the arguments being passed to the script.

     

    I just tested this on a linux system within a bash shell. You can have a script with two read statements (read is one way to prompt a user for input inside of a script). For example, my bash script:

    #!/bin/bash

     

    echo hi

    read -a VAR1 -p "var one: "
    echo var1=$VAR1

    read -a VAR2 -p "var two: "
    echo var2=$VAR2

     

    But I have been unable to find a command that echo's both values into the script and have the script recognize them as values for each one of those read prompts. It seems like it takes a value for the first var and exits with no data for the second var:

     

    Two of the few commands I used. Note: Also, values with spaces do not seem to be fully assigned to var1.

    echo "abc" "tes" | ./testReads.sh

    ./testReads.sh < <(echo "abc tes")

     

     

    Example of script that assigns the variables to the arguments being passed to the script:

    #!/bin/bash

    echo hi
    VAR1=$1
    VAR2=$2
    echo var1=$VAR1
    echo var2=$VAR2

     

    Then execute with:

    ./testReads2.sh "this is one" "this is two"

     

    Regards,
    Gregg