I have a program that has ill effects if run from .bashrc and I've dug deeper and found a minimal reproducible example.
The code below will print the elapsed time every second. If I run this program any time well after boot it outputs sequential seconds, as expected. If I run this program immediately after boot, manually or with .bashrc, the seconds in the output will skip at some point; from .bashrc at 24 they skip to 37 (then continue on as expected 38, 39...), if I run it manually from a shell it happens at some earlier time, depending on how long after boot I run it.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (int argc, char *argv[])
{
int start_time = time(NULL);
int diff = 0;
int prev = 0;
while (1)
{
diff = difftime(time(NULL), start_time);
if (diff != prev)
{
printf("Time: %d\n", diff);
}
prev = diff;
}
}
What could cause this?
hundreds of similar questions - That's fine, I've seen numerous ways in various posts and articles, but bashrc has been presented as one of them. Why do you suggest otherwise? I do not understand what you think is pointless?
– user120300 Jan 08 '21 at 07:48man bash
says " ~/.bash_profile The personal initialization(sic) file, executed for login shells ~/.bashrc The individual per-interactive-shell startup file" – Milliways Jan 08 '21 at 09:33