Shell scripting in bitbake execution procedure - shell

I am just tying to understand the bitbake build system.
I have a doubt regarding how shell functions/task gets executed.
I am going through below documentation https://docs.yoctoproject.org/bitbake/
In a part of documentation it says shell scripts are executed by /bin/sh.
In another part of documentation it says "BitBake writes a shell script to ${T}/run.do_taskname.pid and then executes the script".
What is run.do_taskname.pid?what exactly does it do?what exactly happens when bitbake encounters a shell script?
Thanks in advance

Related

bash script overrides hard coded variables in executed second script

I'm calling Uncle. I'm attempting to manipulate variables that have hard coded values in a second bash script I am calling. I have no control over the script and am building a wrapper around it to adjust some build behavior before it finally kicks off a yocto build. I'm not sure what else to try after reading and trying numerous examples.
Examples of the situation:
build.sh calls build2.sh
IS_DEV=1 ./build2.sh #trying to override value
build2.sh
IS_DEV=0 # hardcoded value
echo $IS_DEV
# always results in 0.
I have also tried export IS_DEV=1 before calling build2.sh.
I'm sure this is pretty simple, but I cannot seem to get this to work. I appreciate any assistance. Is this possible? I'm using GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu) on Ubuntu 16.04.4 LTS.
Oh, I have also tried the sourcing technique with no luck.
IS_DEV=1 . ./build2.sh
IS_DEV=1 source ./build2.sh
Where am I getting this wrong?
Much appreciated.
If you can't modify the script, execute a modified version of it.
sed 's/^IS_DEV=0 /IS_DEV=1 /' build2.sh | sh
Obviously, pipe to bash if you need Bash semantics instead of POSIX sh semantics.
If the script really hard-codes a value with no means to override it from the command line, modifying that script is the only possible workaround. But the modification can be ephemeral; the above performs a simple substitution on the script, then passes the modified temporary copy through a pipe to a new shell instance for execution. The modification only exists in the pipeline, and doesn't affect the on-disk version of build2.sh.

What does "shell out" or "shelling out" mean?

As used in these examples, for instance:
shell out to bundle from inside a command invoked by bundle exec
or
shell out to a Ruby command that is not part of your current bundle,
http://bundler.io/man/bundle-exec.1.html
or
i'm shelling out to the heroku command in the rake task
https://github.com/sstephenson/rbenv/issues/400
It means executing a subprocess using backticks (as in `command`), the system call, or other similar methods. These execute the process in a sub-shell, hence the name.
You can find a lot more details in this answer: https://stackoverflow.com/a/18623297/29470
Spawning a pipeline of connected programs via an intermediate shell —
a.k.a. “shelling out”
http://julialang.org/blog/2012/03/shelling-out-sucks/
And the related reddit comment thread: http://www.reddit.com/r/programming/comments/1bwbyf/shelling_out_sucks/
So, from what I can gather, I presume it means "going out from the context of the executing program, to the surrounding program, or execution environment", in broad terms. Usually you go out to the unix shell, hence the term shell out.

Jenkins skips build shell command

I've made freestyle Jenkins Job. In the configurations I've added Build step execute shell with simple command echo "HELLO WORLD". When I build the job this shell command I think is never executed.I got no HELLO WORLD output there are also no shell errors and such. Can you tell me possible reasons why this is happening.
What kind of shell are you using?
I've had the same kind of problem with tcsh - a command was never executed (not even echoed with the -x option). As it turned out, it was because there was no "newline" character after that command, and with tcsh that seems to be a problem.

Check if a script really requires specific shell to run?

I should deploy some scripts that have been written for bash to various Linux/Unix machines where I may not have bash natively available.
I do not know if the original writer really required bash to run the scripts or it's just because it's default shell in modern Linuxes.
Do you know of any script, application or online service that takes as input a shell script, does some syntax checks using the grammar for several common shells and returns as output some kind of validation estimate like "This script should be run under one of the following shells: ash, bash, ksh, zsh".
I don't know of any tool that does what you're asking for, but there is one called checkbashisms that can at least check for non-portable syntax. IIRC, it's packaged in Ubuntu as part of the devscripts package.
Ubuntu also made the switch to having dash be the default shell and wrote a helpful page about coping with the change of making Dash be /bin/sh. I've found it to be a good reference.

How to link shared library in shell script?

I have wrote a simple shell script where I have only mentioned the following line
export LD_LIBRARY_PATH=/home/lib/
I want to run one program for which I have to link with this library ,before running the program I am running this shell script ,but after this the program is not working it showing the linking error and when I am doing following line it showing nothing
echo $LD_LIBRARY_PATH
but,when I am doing it in shell normally ,it is working.
Can any one tell why this shell script is not working.what is the concept behind it.
Thanks
If you want to run a script for the purpose of modifying environment variables you need to source the script rather than run the script. Running the script starts a new instance of w/e shell is used to run the script, when it returns, all environment variables are back to the way they were before you ran it. Doing "source script.sh" actually runs the commands in the script in your current shell.

Resources