Passing user input value from batch file to shell script

I have a task where I have to write a batch script in which I take input from user and call a shell script from there passing the user input value. Any idea how I can achieve this.

Below is the bat file where I take input from user and finally call the shell script named test(test.sh) which contains curl command

@echo off
set /p technology="Enter technology: "
set /p job_name="Enter job name : "
set /p url="Enter url : "
test.sh

2 answers

  • answered 2022-01-21 08:35 user1934428

    Since according to your tags, the shell script is a POSIX shell, and the Batch script is Windows batch, you can take the advantage that Windows puts the variables it sets by default into the environment. Hence the variables should be parameter-expandable inside your shell script as $technology etc.

  • answered 2022-01-21 11:19 Himanshu Raj

    Thank you for your response. The answer I was looking for is

    in batch script

    @echo off
    set /p technology="Enter technology: "
    set /p job_name="Enter job name : "
    set /p url="Enter url : "
    test.sh %technology% %job_name% %url%
    

    While in the shell script

    echo "technology = $1"
    echo "job name = $2"
    echo "url = $3"
    

    The reason for passing value this way is, I wanted to pass value received from user. Here $1, $2, $3 refers to the values passed according to their passed parameters.

    While in the shell script with curl command

    "url" : "'$3'"
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum