• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

cant use & in bash

Hi
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(){

$CMD_SUDO  $CMD_MYSQL1_START ;

}


now with bellow


while true
do

### 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}"
menuitem=$(<"${INPUT}")
# make decsion
case $menuitem in
       
        Start_mysql1 ) start_mysql1;;
               Exit) echo "Bye"; break;;
esac



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...

thanks





0
fosiul01
Asked:
fosiul01
2 Solutions
 
TintinCommented:
Remove the & from the declare and call the function in the background, ie:

Start_mysql1 ) start_mysql1 & ;;

Open in new window

0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Or hide the & by putting it in the function, remove it from the declare like tintin suggests:

$CMD_SUDO  $CMD_MYSQL1_START &

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now