Forked from zfenj/gist:43dc107ab0685343d558d2c8024081fd
Last active
April 10, 2023 00:04
-
-
Save nfekete/5956fd64687940c4019dd084ff2834a9 to your computer and use it in GitHub Desktop.
Zsh: Get Filename or Extension from Path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://zaiste.net/zsh_get_filename_extension_path/#!/bin/zsh | |
# Filename | |
fullpath="/etc/nginx/nginx.conf" | |
filename=$fullpath:t | |
echo $filename | |
# result: nginx.conf | |
# Path | |
fullpath="/etc/nginx/nginx.conf" | |
thepath=$fullpath:h | |
echo $thepath | |
# result: /etc/nginx | |
# Filename without path and extension | |
fullpath="/etc/nginx/nginx.conf" | |
filename=$fullpath:t:r | |
echo $filename | |
# result: nginx | |
# Filename with path without extension | |
fullpath="/etc/nginx/nginx.conf" | |
filenameandpath=$fullpath:r | |
echo $filenameandpath | |
# result: /etc/nginx/nginx | |
# Fileextension | |
fullpath="/etc/nginx/nginx.conf" | |
ext=$fullpath:t:e | |
echo $ext | |
# result: conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment