Skip to main content
Javier1
Principal
June 7, 2021
Solved

How can i use Build variables? pre-build shell script

  • June 7, 2021
  • 3 replies
  • 2944 views

I want the IDE to save inside a buildinfo.h various const strings containing build timestamp names and other system variables.

0693W00000BaHb5QAF.pngBut im unable to use them inside my pre-build script:

#!/bin/sh
echo "this is the pre-build script!:D"
 
set _current_date=${current_date}
echo ${current_date}
echo ${_current_date}
echo "static const char BUILD_INFO[] = \"build_date=_current_date\";" > buildinfo.h

The pre-build script creates the build.infofile but the variable current_date is not shown...

0693W00000BaHcwQAF.png0693W00000BaHccQAF.png

This topic has been closed for replies.
Best answer by Pavel A.

The eclipse variables can be substituted in the command line, but not in the script file itself.

Try to change the command so:

cd..;./script.sh ${current_date}

and in the script:

#!/bin/sh
echo "this is the pre-build script!:D"
 
set _current_date=$1
.........

3 replies

Javier1
Javier1Author
Principal
June 7, 2021

I first tested

#!/bin/sh
 echo "this is the pre-build script!:D"
 
 echo "static const char BUILD_INFO[] = \"build_date=${current_date}\";" > buildinfo.h

and this got generated inside buildinfo.h:

static const char BUILD_INFO[] = "build_date=";

 :(

hit me up in https://www.linkedin.com/in/javiermuñoz/
Javier1
Javier1Author
Principal
June 7, 2021

It works when i use the date GNU command but i would like to use the IDE build variables.

echo "this is the pre-build script!:D"
cd Core/Inc
NOW=$(date +"%Y-%m-%d_%T")
echo "static const char BUILD_INFO[] = \"build_date="$NOW"\";" > buildinfo.h

hit me up in https://www.linkedin.com/in/javiermuñoz/
Pavel A.
Pavel A.Best answer
June 7, 2021

The eclipse variables can be substituted in the command line, but not in the script file itself.

Try to change the command so:

cd..;./script.sh ${current_date}

and in the script:

#!/bin/sh
echo "this is the pre-build script!:D"
 
set _current_date=$1
.........