Any way to stop `cargo run` clutering up file `~\ .bash_history`

cargo run for example dumps lots of cd commands into file ~/.bash_history
e.g.

cargo run
cd '/home/D6204/Rust'
cd '/home/D6204/PNG/src'
cd '/home/D6204/Rust'
cd '/home/D6204/PNG/src'
cd '/home/D6204'
cd '/home/D6204/Rust'
cd '/home/D6204'

Any way to stop this? After repeated runs the entire history file becomes overwritten with a huge list of cd commands.

This does not happen for a typical Rust program. Are you running a program that shells out to bash? Or could these commands be coming from its build script, or the build script of one of its dependencies?

I fire up a bash terminal, then execute command cargo run then immediately see the cd commands in my ~/.bash_history... I don't know if this is relevant, but I downloaded cargo and rustc from a Debian repo... My cargo version is 1.42.1, rustc version 1.41.1

Does this happen only for a particular project, or does it happen even in a new "Hello World" project with no dependencies? What is the relationship between the Rust and PNG directories, and what directory are you running Cargo in?

I tried testing this by installing Cargo from the Debian sid repository and running cargo run from a bash shell, and I did not see any new entries in ~/.bash_history.

Nothing gets dumped into ~/.bash_history when I do a simple "hello world" run.
The "dump" results from my doing cargo run using the lodepng crate examples I've been playing with... i.e., those I downloaded from crates.io.

I ran all the examples in the lodepng repo, and I still can't reproduce this behavior.

Can you share the exact Rust code that you are running when this problem happens? Does it happen to run a shell, or use any programs like make that use the shell to execute commands? Have you tried anything to narrow down which part of the program causes the behavior you're seeing?

here's the main.rs in dir PNG

use std::*;

fn main() {

const W: usize = 300;
const H: usize = 600;
let mut img: [ [u8; 4]; W*H] = [[0_u8; 4]; W*H];

for h in 0..H {
    for w in 0..W {
      if       h/200 ==0 { img[h*W +w ] = [255_u8,  0_u8,  0_u8,255_u8] ; }
      else if  h/200 ==1 { img[h*W +w ] = [  0_u8,255_u8,  0_u8,255_u8] ; }
      else if  h/200 ==2 { img[h*W +w ] = [  0_u8,  0_u8,255_u8,255_u8] ; }
}  }
//Saving image example
// The buffer can be a slice of any type as long as it has 4 bytes per element (e.g. struct RGBA or [u8; 4]).
lodepng::encode32_file("out.png", &img, W, H) ;

println!("out.png !");

// Loading an image example (more examples in the examples/ dir)
match lodepng::decode32_file("out.png") {
        Ok(image)   => println!("image.W= {}  image.H= {} ..image.buffer[0]= {}", image.width, image.height, image.buffer[0] ),
        Err(reason) => println!("Could not load, because: {}", reason),
    }

}

That's weird. I don't see any extra history entries when I run this on my machine, and there doesn't seem to be anything in your code or in the lodepng crate that would cause it. In particular, there's no reference in this program to the ../Rust directory that appears in your history.

Is it possible that these are commands you entered in the terminal, and that it is your shell that is for some reason saving them multiple times to the history?

If you could reproduce it on free open CI services such as github actions or gitlab ci, that would be a good way for us to confirm this problem.

I've never seen this behavior. I don't think a command run from a shell can even influence its parent shell like that. Plus, Cargo only uses root of the crate as the current dir and doesn't change to src/.

Are you sure it's not your code editor, terminal integration or some other piece of software?

Its totally weird...I've never seen this behavior before. Other than cargo and rustc all the other software in use (text editor and bash shell) I've been using for years. Also, there is no need for any cd commands once cargo is called within the upper part of a specific project directory.

"Totally weird" things happen all the time.

It might possibly help if you stated exactly what commands you have been running, on what operating system and version, with what source code that is being built.

From the ground up.

Otherwise nobody has a chance to reproduce this effect.

Just for the record, I have not seen it either. Across multiple Rust/Cargo versions on Windows WSL, MacOS, Linux on Raspberry Pi.

However, I have never used any OS packaging system to install Rust. I always just use rustup.

I'm using MX Linux (see distrowatch.com for info) .. The only thing I do is use the MX File manager to open a terminal at the directory created by a previous 'cargo new' call. Then, after editing src/main.rs in my text editor, inside the terminal window I execute 'cargo run' ... I do this very same procedure all the time, just before compiling/ running C++ and Go code, and never once saw any 'cd' cmds cluttering up ~/.bash_history ...only the cmds I enter in the terminal window appear in ~/_history...and inside the terminal window I dont execute any cd commands. The cd cmds always appear after I enter 'cargo run' .. weired !

Is it possible the file manager is doing that when you open the terminal window?

I run on Debian, and I've never seen anything like this, but I mostly live in the bash shell and don't often use gui file managers.

Ah ha, as I thought. That could be the "totally weird" thing we are looking for. Never heard of "MX Linux" before. Who could know what it does.