ubuntu - Replacing substring with other text in variable inside a bash script -


this question has answer here:

i've been trying write bash script. part of supposed replace part of string nothing.

here's i'm trying do

$dbname=$1 $dbnameactual="${$dbname/.sql/}"  date echo $dbnameactual 

i tried number of suggestions stack. got nowhere. tried adding sed, didn't seem work.

the idea have script, , takes in db import file name, db250317.sql , outputs db250317 .

i'm running ubuntu 16.04 lts.

you don't put $ twice in expression, , don't put $ before variable you're assigning (this isn't php or perl). should be:

dbnameactual="${dbname/.sql/}" 

also, if thing you're trying delete @ end, can use % remove it:

dbnameactual="${dbname%.sql}" 

also remember quote variable when use later, in case filename contains spaces. should quote variables, unless have specific reason not to.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

nginx - phpPgAdmin - log in works but I have to login again after clicking on any links -