bash: working with strings
This is a wiki page. Be bold and improve it!
If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.
string length:
${#string}
${string:position}
${string:position:length}
${string%substring}
shortest:
${filename#*/}
${filename#/*}
longest:
${filename##*/}
${filename##/*}
#!/bin/bash
# E.g. PWD = "/home/user/scripts/myproject"
PWD=`pwd`
project=${PWD##*/}
#$project = "myproject"
echo "$project"
${string/pattern/replacement}