executing shell command in background from script

前端 未结 4 501
误落风尘
误落风尘 2020-11-27 17:40

how can I execute a shell command in the background from within a bash script, if the command is in a string?

For example:

#!/bin/bash
cmd=\"nohup my         


        
4条回答
  •  盖世英雄少女心
    2020-11-27 18:11

    Leave off the quotes

    $cmd &
    $othercmd &
    

    eg:

    nicholas@nick-win7 /tmp
    $ cat test
    #!/bin/bash
    
    cmd="ls -la"
    
    $cmd &
    
    
    nicholas@nick-win7 /tmp
    $ ./test
    
    nicholas@nick-win7 /tmp
    $ total 6
    drwxrwxrwt+ 1 nicholas root    0 2010-09-10 20:44 .
    drwxr-xr-x+ 1 nicholas root 4096 2010-09-10 14:40 ..
    -rwxrwxrwx  1 nicholas None   35 2010-09-10 20:44 test
    -rwxr-xr-x  1 nicholas None   41 2010-09-10 20:43 test~
    

提交回复
热议问题