Assignment | |
---|---|
Assign value to variable if variable is not already set, value is returned.Combine with a : no-op to discard/ignore return value . |
${variable="value"} : ${variable="value"} |
This file contains hidden or 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
#!/bin/bash | |
# file path example | |
FILE=/home/user/src.dir/prog.c | |
echo ${FILE#/*/} # ==> user/src.dir/prog.c -- remove everything BEFORE the SECOND '/' | |
echo ${FILE##*/} # ==> prog.c -- remove part BEFORE LAST '/' | |
echo ${FILE%/*} # ==> /home/user/src.dir -- remove everything AFTER the LAST '/' | |
echo ${FILE%%/*} # ==> nil -- remove everything AFTER the FIRST '/' (returns empty string) | |
echo ${FILE%.c} # ==> /home/user/src.dir/prog -- remove everything AFTER '.c' |