0

I'm making a minishell in C. I don't know what is the best way to order the strings. The idea is that by running the C program and typing "export" with no arguments, it simulates the output that bash does (declare -x "text").

How can i order it? Since export in bash orders the output of the env

Thanks

Edit:

I have this for the moment so that I can display it (without ordering), where g_shell->env is a global environment variable

int i = 0;
while (g_shell->env[i])
{
  printf("%s\n", g_shell->env[i]);
  i++;
}
7
  • 2
    This has been asked several times this month and the answer is sort them however you want, there is no difference, no one cares. Commented Sep 11, 2021 at 10:28
  • What would the code look like? I'm having problems. Or if there is any link from stackoverflow to be able to base myself Commented Sep 11, 2021 at 10:49
  • From what I understand, if you give your C program the input "declare -x text", it should store 'text' in the list of variables but in sorted order so that when you do a export, it prints out variables in sorted order. Is that right? Commented Sep 11, 2021 at 10:49
  • That is correct, although what I have is a char **, not a list. It would be to order it this way Commented Sep 11, 2021 at 10:53
  • You can use qsort() inbuilt function to sort an array of strings (char **). See this link: stackoverflow.com/a/23189704 Commented Sep 11, 2021 at 10:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.