Sample Header Ad - 728x90

Shell script: Using variables makes command fails ( substituting values of variables manually ; command works fine )

0 votes
1 answer
78 views
In a bash script: jenkins_folder=cut -d "|" -f1 -s input.csv jenkins_url='https://url.com:8181/jenkins/view/ ' echo "jenkins_folder : ${jenkins_folder}" for job in java -jar jenkins-cli.jar -s ${jenkins_url}${jenkins_folder} list-jobs ${jenkins_folder} do echo "Job name:: ${job} ****" java -jar jenkins-cli.jar -s ${jenkins_url}${jenkins_folder} get-job ${job} > job.xml done is giving following output jenkins_folder : Platform-X.X.X-SPO-MyPD-Integration-Dummy ****ame:: NH-AccountManagementAudit-Consumer-MyPD-Integration-DUMMY-Reporting '; perhaps you meant 'NH-AccountManagementAudit-Consumer-MyPD-Integration-DUMMY-Reporting'? And when I substitute values of all variables and run following command; it works fine java -jar jenkins-cli.jar -s https://url.com:8181/jenkins/view/Platform-X.X.X-SPO-MyPD-Integration-Dummy get-job NH-AccountManagementAudit-Consumer-MyPD-Integration-DUMMY-Reporting > job.xml I have wasted too much time on this. I even tried using eval function but no luck. Please help. Thanks to @Kusalananda when I am trying to echo job name its printing output in wierd fashion.. I feel this is the root cause.. but not sure why that is happening If I try to shorten the length of variable job (using substring); then it prints fine. Hence, if value of job is long; it is creating problem
Asked by Deepak Singhal (103 rep)
Apr 24, 2023, 10:55 AM
Last activity: Apr 24, 2023, 12:21 PM