Bash Notes - Popd/Pushd & Return Value
Popd/Pushd
These two commands are usually used to change the directoy.
Pushd
- Move to a certain directory, and store the current directory at the top of a stack.
Popd
- Read the directory from the stack, move to it, and then delete the directory from the stack.
The first time using Pushd, the current directory would be stored at the bottom of the stack since the stack is empty. If the command is used again, another directory would be stored on top of the first directory.
Example:
1 |
|
Result:
Return Value
If we want to get the return value of a command and store it in a variable, usually we use the following command:
1 |
|
command represents the command which we want to get the return value from. variable is where we store the return value. returnvalue would be ultimately set to the return value of this command.
To retrieve the value, we could use the following command:
1 |
|
Example:
1 |
|
Result:
Bash Notes - Popd/Pushd & Return Value
https://rigel.github.io/BashNote01/