1

My script fetches the names of directories in a path and stores in a text file.

#!/bin/bash
MYDIR="/bamboo/artifacts"
DIRS=`ls -d /bamboo/artifacts/* | cut -d'/' -f4 > plan_list.txt`

plan_list.txt:
**************

PLAN1
PLAN2
PLAN3

Now I am trying to pass each of these directory names to a URL to get output like this.

http://bamboo1.test.com:8080/browse/PLAN1
http://bamboo1.test.com:8080/browse/PLAN2
http://bamboo1.test.com:8080/browse/PLAN3    

The script to do that doesn't seem to work

bambooServer="http://bamboo1.test.com:8080/browse/"
for DIR in $DIRS
do
  echo `$bambooServer+$DIR`
done

Could someone please tell me what I am missing here? Instead of storing the ls command output to a plan_list.txt file i tried passing to array but that didn't work well too.

1 Answer 1

1
DIRS=`ls -d /bamboo/artifacts/* | cut -d'/' -f4 > plan_list.txt`

DIRS is just an empty variable since your command is not producing any output and just redirecting output to plan_list.txt.

You can rewrite your script like this:

#!/bin/bash

mydir="/bamboo/artifacts"
cd "$mydir"

bambooServer="http://bamboo1.test.com:8080/browse/"
for dir in */
do
  echo "$bambooServer$dir"
done

*/ is the glob pattern to get all the directories in your current path.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.