dir=/home/smith/Desktop/Test
parentdir="$(dirname "$dir")"
Works if there is a trailing slash, too.
More Related Contents:
- How can I get the source directory of a Bash script from within the script itself?
- Listing only directories using ls in Bash?
- How can I get the directory where a Bash script is located from within the script itself?
- How do I get the directory where a Bash script is located from within the script itself?
- Save file to specific folder with curl command
- How to use Bash to create a folder if it doesn’t already exist?
- While loop stops reading after the first line in Bash
- How to detect if a script is being sourced
- Why does “local” sweep the return code of a command?
- Renaming files in a folder to sequential numbers
- How to generate random number in Bash?
- How to skip the for loop when there are no matching files?
- “Invalid Arithmetic Operator” when doing floating-point math in bash
- Using sed to mass rename files
- Sort a text file by line length including spaces
- How to get script directory in POSIX sh?
- List files not matching a pattern?
- Commenting in a Bash script inside a multiline command
- How to parallelize for-loop in bash limiting number of processes
- Script to get the HTTP status code of a list of urls?
- What is your single most favorite command-line trick using Bash? [closed]
- Execute a shell function with timeout
- How to parse $QUERY_STRING from a bash CGI script?
- Read a file by bytes in BASH
- How can I print each command before executing? [duplicate]
- Using Bash to display a progress indicator (spinner) [duplicate]
- Can parameter expansion be nested in Bash? [duplicate]
- reverse the order of characters in a string
- What’s the cmd/PowerShell equivalent of back tick on Bash?
- Why doesn’t my terminal output unicode characters properly?