-1

Script:

 #!/bin/bash

 mydir="/bamboo/artifacts"
 cd "$mydir"
 job="-JOB1"

 for dir in */
    do
       bambooplan=`echo $dir | sed 's/\/$//g'`$job
       echo $bambooplan
    done

Output:

   LERST-TSTREDAPIDB2WIN4-JOB1
   LERST-TSTREDAPIDB2WIN5-JOB1
   CA-TSTALLSQLWIN3-JOB1
   CE-CSW-JOB1
   CE-SNAP-JOB1

I want to pass this to a file. I tried the commands below and it gives permission denied error. Could someone help me figure what I miss here?

echo $bambooplan > result.txt
$bambooplan > result.txt
2
  • Not an exact duplicate, but look at this: stackoverflow.com/questions/18612603/…. And mywiki.wooledge.org/BashFAQ/014 Commented Feb 5, 2016 at 22:30
  • Your syntax is correct. Permission denied means you don't have write permission to result.txt, or the file doesn't exist and you don't have write permission to the directory. Commented Feb 5, 2016 at 23:22

2 Answers 2

1

I tested your code with the first 'writing line' (echo $bambooplan > result.txt) and worked perfect for me, only i would change echo $bambooplan > result.txt to echo $bambooplan >> result.txt, otherwise, you will overwrite the entire file in each iteration, keeping only the last one.

Be aware that your code writes INSIDE /bamboo/artifacts and you wrote the file path as /bamboo/artifacts, an absolute path, not a relative one -> bamboo/artifacts, so, maybe, you're trying to write in a folder where you don't have writing permissions and need to chmod them.

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

Comments

0

Redirect just to your defined file by using > as you specified or >> if file already already exists and contains data. Regarding to the permission, just exchange script's rights thru chmod command.

for instance :

chmod 755 scriptname

Same process to change output file's permission.

1 Comment

The script must already have the correct permissions, since he's executing it.

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.