cant use & in bash

Posted on 2011-10-25
Last Modified: 2012-05-12
I am trying to use dialog box in bash script and trying to use this command

declare -rx  CMD_SUDO="/usr/bin/sudo";
declare -rx  CMD_MYSQL1_START="/usr/local/mysql1/bin/mysqld_safe --defaults-file=/usr/local/mysql1/my.cnf & "

function  start_mysql1(){



now with bellow

while true

### display main menu ###
dialog --clear  --help-button --backtitle "Mysql Administration Console" \
--title "[ M A I N - M E N U ]" \
--menu "You can use the UP/DOWN arrow keys, the first \n\
letter of the choice as a hot key, or the \n\
number keys 1-9 to choose an option.\n\
Choose the TASK" 20 50 4 \
Start_mysql1 "Start Mysql1" \
Stop_mysql1 "Stop Mysql1" \
Exit "Exit to the shell"  2>"${INPUT}"
# make decsion
case $menuitem in
        Start_mysql1 ) start_mysql1;;
               Exit) echo "Bye"; break;;

Now , i was hoping that :
after it was start mysql1 with  CMD_MYSQL1_START command, it will come back to main screen.

which it does but then mysql process die with
/usr/local/mysql1/bin/mysqld: Too many arguments (first extra is '&').

so mysql thinking that i am trying to use file name : my.cnf$

but when i execute the line

/usr/local/mysql1/bin/mysqld_safe --defaults-file=/usr/local/mysql1/my.cnf &

its works as it will start mysql in background.

so in bash script how will tell the script that not to add "&" with the script name ..
bascially want i want is : in some how ..
the myql will start and after that the script will come back to main screen . (main menu)

if i am not clear, please ask me...


Question by:fosiul01
    LVL 48

    Accepted Solution

    Remove the & from the declare and call the function in the background, ie:

    Start_mysql1 ) start_mysql1 & ;;

    Open in new window

    LVL 37

    Assisted Solution

    by:Gerwin Jansen
    Or hide the & by putting it in the function, remove it from the declare like tintin suggests:


    Open in new window


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now