2

I am trying to add custom variable in a bash script alias command and not able to do it

I added the following in .bash_profile file

alias mvdb='mv ~/dbs/aw ~/dbs/aw-$1'

In the command line I am trying to run a script

mvdb "2017OCT20"

I want the folder named aw to be renamed as aw-2017OCT20 when I run command

1 Answer 1

7

This is a job for a function.

mvdb() {
    mv ~/dbs/aw ~/dbs/aw-"$1"
}
1
  • 1
    i added the alias to bash profile with a single line code, alias mvdb='mv ~/dbs/aw ~/dbs/aw-$1' So, Can I write the function that you had mentioned directly in .bash_profile, or do i need to create a new file containing only this function
    – Masade
    Oct 22, 2017 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.