I'm running ubuntu on WSL, and now I want to make my command to start up my php server(Nginx, mysql, php). Right now everytime I boot my pc I always run sudo service nginx start, sudo service mysql start, and the php.

I want to make my own custom command that when I run it, it will execute the starting services command. Until this point I know how to make custom command. But the problem is, I have 2 projects that need 2 different php version(One 7.1 and the other is 7.3). Can I make a command that accept arguments and run the service based on the arguments.

My expectation:

customcommand 7.1 will start nginx, mysql, and php7.1-fpm services

customcommand 7.3 will start nginx, mysql, and php7.3-fpm services

I know, I can just make different commands like customcommand7.1 and customcommand7.3. But if I can just make 1 command, why not?

Sorry if my question is a dump question. and Thanks! :D

  • in your case, just use a if / case statement (and don't forgot to start it using sudo)
    – damadam
    Dec 16 '19 at 15:06
  • @damadam how do you if / case in bash file? Dec 16 '19 at 15:25

Just save it in file some like function.sh and run it like: bash function.sh


customcommand () {
    sudo service nginx start
    sudo service mysql start
    sudo service php$1-fpm start
    # ... use switch case
    echo "Run v$1"

# this command execute version 7.1
customcommand 7.1

if it work, put this in .bashrc if it linux, or .bash_profile in mac


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.