Hello I'm brand new to shell scripting, so sorry if this is trivial.
How do you use printf command with the -v option?
In our deployment.sh file we have this line
printf -v BITBUCKET_COMMIT_str %q "$BITBUCKET_COMMIT"
echo 'Initializing new deployment'
printf -v BITBUCKET_COMMIT_str %q "$BITBUCKET_COMMIT"
echo "commit string $BITBUCKET_COMMIT_str"
When the Bitbucket pipeline runs, it always fails at this line. With the error printf -v is an illegal option.
Error from Bitbucket
Initializing new deployment
commit string
deployment.sh: 28: printf: Illegal option -v
bash: -c: line 1: syntax error: unexpected end of file
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! XXXXX deploy: `sh deployment.sh`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the XXXX deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/XXX-debug.log
I've tested the printf -v command in a local terminal and it works fine, so I don't know why it doesn't work in the Bitbucket build pipeline. I've tried replacing printf with just a variable, but then I get a syntax error later on in the file. I think that's because we try to use the variable as in input for another command
"bash -s $BITBUCKET_COMMIT_str" <<\HERE
echo "TEST MADE IT HERE"
BUILD_FOLDER="BUILD_$BITBUCKET_COMMIT"
echo "Build: $BUILD_FOLDER"
...
HERE
On another note I'm not entirely sure what the above script is trying to do. I haven't been able to find what the bash -s command does. I think this command is trying to append a file with the contents of the HERE block. The script inside the HERE block doesn't seem to run unless I change << to >> The code inside the HERE block seems to run. But from what I understand about the << that change doesn't really make sense.
Any help would be greatly appreciated. Most of my team is on holiday so I'm having a tough time with this. Thanks in advance :)