for instance

function mysqldumpSafe {adds user and password and dumps}

in ubuntu command line.. how do i run this "mysqldumpSafe" to execute the function?

super noob question...

my .bashrc file

function cleanStatic {

    rm -rf ~/public_html/pub/static/frontend ~/public_html/pub/static/adminhtml ~/public_html/pub/static/_cache ~/public_html/pub/static/deployed_version.txt;

    rm -rf ~/public_html/var/view_preprocessed;

    php ~/public_html/bin/magento cache:flush full_page;


function cleanAll {

    rm -rf ~/public_html/pub/static/frontend ~/public_html/pub/static/adminhtml ~/public_html/pub/static/_cache ~/public_html/pub/static/deployed_version.txt;

    rm -rf ~/public_html/var/view_preprocessed;

    php ~/public_html/bin/magento cache:flush;

    redis-cli -h redis flushall;

    curl -X 'PURGE' -H'X-Magento-Tags-Pattern: .*' varnish;


function deployAll {

    php ~/public_html/bin/magento setup:di:compile;

    php ~/public_html/bin/magento setup:static-content:deploy -s standard;


function deploySafe {

    php ~/public_html/bin/magento maintenance:enable;



    php ~/public_html/bin/magento maintenance:disable;


The bash file sits one directory above public_html but when i'm in public html i can run basic bin commands such as : php bin/magento cache:clean

but since these custom bash commands have like 3 commands in one.. i wanted to figure out how to use them.


https://linuxize.com/post/bash-functions/ explains bash functions in detail.

In general, to run your function, just open a bash terminal, enter the name of the function (mysqldumpSafe in your case) followed by any arguments (space-separated), and press Enter.

| improve this answer | |
  • that's kind of what i was thinking but it doesn't seem to be working. I posted the actual file contents above. @Georgelemental – Supplement Apr 25 '19 at 0:14

The .bashrc file is user-specific, so if you do want to use the function you need to switch your shell to root user via

sudo -i

You will get interactive bash prompt and at that point should be able to use that function

| improve this answer | |
  • do i just write php mysqldumpSafe(); in the terminal? – Supplement Apr 24 '19 at 23:06
  • If this is a bash function, you should write just mysqldumpSafe. – Georgelemental Apr 24 '19 at 23:10
  • @Supplement Bash functions can be invoked directly without parenthesis. Now, why have you mentioned php , though ? Is the function in question actually php code or bash code ? Better yet, can you provide a minimal example so we could understand exactly what you are trying to do ? – Sergiy Kolodyazhnyy Apr 24 '19 at 23:25
  • I'll post it above.. @SergiyKolodyazhnyy – Supplement Apr 25 '19 at 0:12
  • I don't have root access but i think i can use this just like i would use any other bin command, although it doesn't seem to work – Supplement Apr 25 '19 at 0:14

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.