Last active
November 9, 2022 22:25
-
-
Save zfenj/43dc107ab0685343d558d2c8024081fd 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 | |
nginx.conf | |
# Path | |
fullpath="/etc/nginx/nginx.conf" | |
thepath=$fullpath:h | |
echo $thepath | |
/etc/nginx | |
# Filename without extension | |
fullpath="/etc/nginx/nginx.conf" | |
filename=$fullpath:t:r | |
echo $filename | |
nginx | |
# Fileextension | |
fullpath="/etc/nginx/nginx.conf" | |
ext=$fullpath:t:e | |
echo $ext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment