P
P
Pinkman2021-03-31 17:25:38
linux
Pinkman, 2021-03-31 17:25:38

How to set the $ variable? in si program?

I am writing a shell. In the task, it is necessary that after each launch of other programs through my shell, the value of the $? variable is set. And what I don't understand is how to do it? Will the system itself set this variable or should I somehow write its value with handles?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2021-03-31
@famousman204

$? is the exit status of the last program.
In C, it corresponds to the value returned by the main function. The normal termination of the program should return 0, each error usually corresponds to its own code.

P
pfg21, 2021-03-31
@pfg21

exit 0 at the end of main()
exiting main causes the program to exit (generally). and the output value of main is placed in the status variable $?
https://man7.org/linux/man-pages/man1/bash.1.html Special Parameters

C
CityCat4, 2021-03-31
@CityCat4

This variable will be set by the system itself.

Will. If you say. $? is the return code of the last executed command. The return code is set by calling exit()
man exit in general.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question