Escape dollar sign in string by shell script

As you know, a dollar sign marks a variable. You have to take it into account when you are typing it.

You can escape the dollar

./dd.sh "sample\$name.mp4"

or just type it with single quotes

./dd.sh 'sample$name.mp4'

To check if there is a dollar sign in a variable, do

[[ $variable == *\$* ]] && echo 'I HAZ A DOLAR!!!' || echo 'MEH'

Leave a Comment