$?
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). If it doesn’t exist, you should get a number other then 0. The exact number depends on the program.
For many programs you can find the numbers and their meaning in the corresponding man page. These will usually be described as “exit status” and may have their own section.
Related Posts:
- How do I split a string on a delimiter in Bash?
- How to mkdir only if a directory does not already exist?
- How to mkdir only if a directory does not already exist?
- Meaning of “! -S” in shell script
- “No such file or directory” but it exists
- Ubuntu says “bash: ./program Permission denied” [closed]
- Should I put #! (shebang) in Python scripts, and what form should it take?
- Should I put #! (shebang) in Python scripts, and what form should it take?
- How do I copy a folder from remote to local using scp?
- How to concatenate string variables in Bash
- -bash: syntax error near unexpected token `)’
- An example of how to use getopts in bash
- How to delete from a text file, all lines that contain a specific string?
- How do I iterate over a range of numbers defined by variables in Bash?
- How to set ssh timeout?
- commands not found on zsh
- sudo: apt-get: command not found
- How do I iterate over a range of numbers defined by variables in Bash?
- Why do people write #!/usr/bin/env python on the first line of a Python script?
- Using find to locate files that match one of multiple patterns
- “unary operator expected” error in Bash if condition
- What does “-ne” mean in bash?
- How can I declare and use Boolean variables in a shell script?
- Is there a Python equivalent to the ‘which’ command
- How can I declare and use Boolean variables in a shell script?
- How to generate random number in Bash?
- How to check if a variable is set in Bash?
- “[ ]” vs. “[[ ]]” in Bash shell
- How do I split a string on a delimiter in Bash?
- Who can access a file with octal permissions “000” on Linux/UNIX?
- How can I compare numbers in Bash?
- What does the line “#!/bin/sh” mean in a UNIX shell script?
- Open and write data to text file using Bash?
- How do I set a variable to the output of a command in Bash?
- python getoutput() equivalent in subprocess
- Meaning of $? (dollar question mark) in shell scripts
- Is there a TRY CATCH command in Bash
- dquote> result of a execution a program in linux shell
- Using sudo with Python script
- how to fix the issue “Command /bin/sh failed with exit code 1” in iphone
- Run a string as a command within a Bash script
- conditional binary operator expected in shell script
- Block Comments in a Shell Script
- Shell script not running, command not found
- How to get a shell environment variable in a makefile?
- What are the uses of the exec command in shell scripts?
- using rot13 and tr command for having an encrypted email address
- Shell Script: Execute a python program from within a shell script
- sed whole word search and replace
- How do I know the script file name in a Bash script?
- What is the difference between double and single square brackets in bash?
- What is “-bash: !”: event not found”
- What’s the difference betwen the single dash and double dash flags on shell commands?
- How to let ‘cp’ command don’t fire an error when source file does not exist?
- How do I pause my shell script for a second before continuing?
- In the shell, what does ” 2>&1 ” mean?
- subprocess.Popen(): OSError: [Errno 8] Exec format error in python?
- How to substitute shell variables in complex text files
- How can I recursively find all files in current and subfolders based on wildcard matching?
- Curl command for https ( SSL )
- How to exclude a directory in find . command
- “sed” command in bash
- How to exclude a directory in find . command
- How to reload .bash_profile from the command line?
- What is the purpose of “&&” in a shell command?
- Shell Script Syntax Error: Unexpected End of File
- Bash scripting missing ‘]’
- adb shell su works but adb root does not
- What is a list in Bash?
- Given two directory trees, how can I find out which files differ by content?
- adb shell su works but adb root does not
- How to remove the quotes when reading a variable in jq in shell?
- Shell script “for” loop syntax
- Pseudo-terminal will not be allocated because stdin is not a terminal
- screen Cannot open your terminal ‘/dev/pts/0’ – please check
- How to convert a string to lower case in Bash?
- Sorting data based on second column of a file
- zip error – Nothing to do
- How to sort an array in Bash
- What does set -e mean in a bash script?
- Run script on mac prompt “Permission denied”
- How do I get the current username in Windows PowerShell?
- * failed to open vchiq instance
- how to check which version of nltk, scikit learn installed?
- How to split one string into multiple strings separated by at least one space in bash shell?
- Difference between a script and a program?
- Purpose of #!/usr/bin/python3 shebang
- Copy multiple files from one directory to another from Linux shell
- execvp: bad address error
- Python Login Script; Usernames and Passwords in a separate file
- Using grep and ls -a commands
- How to use sed to extract substring
- Running shell command and capturing the output
- Simple PowerShell LastWriteTime compare
- Can pm2 run an ‘npm start’ script
- Best practice for exiting batch file?
- Shell command to monitor changes in a file
- How to run command as user who has /usr/sbin/nologin as Shell?
- Adding a directory to $PATH in CentOS?
- How do I join two named pipes into single input stream in linux