What is $? In shell script? $? is used to find the return value of the last executed command. Try the following in the shell: ls somefile echo $? If somefile exists (regardless whether it is a file or directory), you will get the return value thrown by the ls command, which should be 0 (default “success” return value).
What does $? return in Linux? The return value of a command is stored in the $? variable. The return value is called exit status. This value can be used to determine whether a command completed successfully or unsuccessfully.
How does a shell script return a value?
- Using Echo. You can echo string at the end of your Shell script function.
- Return Exit Status. You may also return an exist status at the end of your shell script function as shown below.
- Using Shared Variable.
How do I return in Linux? return command is used to exit from a shell function. It takes a parameter [N], if N is mentioned then it returns [N] and if N is not mentioned then it returns the status of the last command executed within the function or script. N can only be a numeric value.