Suppose I have a script named dd.sh, and I run it like this
./dd.sh sample$name.mp4 So $1 is the string sample$name.mp4.
echo '$1' // shows $1 echo "$1" // shows "sample.mp4"; want "sample$name.mp4" Then how to process $1 that I can detect whether there is a dollar sign in parameter $1
I want to process the string to sample\$name.mp4 or just detect whether there is a dollar sign in parameter $filename
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With