Find the answer to your Linux question:
Results 1 to 3 of 3
I have a bash script that looks like this bash ./start.sh > ../logs/stdout.log 2> ../logs/stderr.log & STARTED=$! echo "$STARTED" >> ../run.pid wait $STARTED What does the "&" after ../logs/stderr.log do? ...
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Posts
    1

    Bash script help

    I have a bash script that looks like this

    bash ./start.sh > ../logs/stdout.log 2> ../logs/stderr.log &
    STARTED=$!
    echo "$STARTED" >> ../run.pid
    wait $STARTED

    What does the "&" after ../logs/stderr.log do?
    Also, why do I need to put "bash" infront of "./start.sh"

    Thanks!

  2. #2
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    What does the "&" after ../logs/stderr.log do?
    It puts the start.sh script that executed into the background.
    linux user # 503963

  3. #3
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    Quote Originally Posted by ykumar6 View Post
    Also, why do I need to put "bash" infront of "./start.sh"
    If the script is not executable, or if it does not have the command line interpreter (bash, in this case) defined in the script, it needs to know how to run it.

    To see if it is executable, you can do:
    Code:
    ls -l start.sh
    In the below output, the three x's mean the script is executable by owner, group, and all:
    Code:
    -rwxr-xr-x  1 root root  243  Dec 1 2011 myscript.sh
    Assuming you have permissions to do it, you can make a script executable with:
    Code:
    chmod +x start.sh
    The command line interpreter is probably already defined at the top of the script. For example, a script's command line interpreter could look like one of:
    Code:
    #!/bin/sh
    
    #!/bin/bash
    
    #!/usr/bin/env sh
    
    #!/usr/bin/perl
    The first two would try to execute the script using bash (or sh, which usually is a symlink to bash) located in the /bin dir. The third will look in your PATH for sh (which is smarter than hard-coding it to /bin), and the 4th will use perl.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...