string

bash: working with strings

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}

Syndicate content