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
CodePudding user response:
Consider modifying test.sh such that it takes command line arguments, and then passing the provided values when you call it in the batch script.
You can read about cli args and shell scripts here
CodePudding user response:
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.
CodePudding user response:
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.
