Ubuntu – How to run a shell script from bashrc file

bashbashrccommand linescripts

What I basically want to achieve is to type in a custom command in the terminal and a specific shell script should run each time.

I could achieve the above requirement with folders,by modifying the bashrc file like below

alias myScripts="cd /home/arun/Desktop/scripts"

Now when I try to do the same with a bash script by modiying the bashrc file as given below,

alias masterScript="bash /home/arun/Desktop/scripts/myMasterScript.sh"

now when I type masterScript im getting the following error:

"bash : No such file or directory" error

How can I correct this?

Best Answer

Just create a function:

function masterScript()
{
    if [ -e /home/arun/Desktop/scripts/myMasterScript.sh ]
    then
        bash /home/arun/Desktop/scripts/myMasterScript.sh
    fi
}

And make sure your script is executable:

chmod 755 /home/arun/Desktop/scripts/myMasterScript.sh
Related Question