biralavor / 42_minishell

minishell, a 42 school team project to rebuild a tiny bash, using C language. Build with @Thais-Malheiros
MIT License
3 stars 0 forks source link

environment init #100

Closed biralavor closed 3 months ago

biralavor commented 3 months ago

Step 1: Copy System Environment Variables

Since your main function doesn't accept parameters, you won't directly pass the environment to execve. Instead, you'll use execve to replace your current process with your shell's main program, which will inherit the environment from the parent process. This is typically how shells operate—they don't usually need to explicitly copy the environment; they inherit it.

Step 2: Manipulate Environment Variables

Once you have the environment variables, you can manipulate them as needed. For instance, you might want to store them in a hash table for easy access and modification.

Step 3: Implementing the Hash Table

You'll need to implement a hash table to efficiently store and retrieve environment variables. Here's a simplified example of how you might define and initialize such a hash table

Step 4: Using getenv to Populate the Hash Table

Before manipulating the environment variables, you can iterate through them using getenv and populate your hash table

biralavor commented 3 months ago

hash_maker, using the mjb2 algorith here: https://github.com/biralavor/42_minishell/commit/2b6dbf04d764a6489011afa6d80aa8fc4cc45cb8 unsigned long hash_maker(const char *key, int size); However, since the export command need to sort the environment variables, applying the hash into the t_env_table increased too much the code complexity for such low system variable quantity (below 100). In other words: it was a bad trade-off. Therefor, I'll refactor the code to simplify the environment linked list t_env_entryand remove the hash_maker usage.