How to use WAIT in a bash file

Posted on 2011-04-19
Last Modified: 2012-05-11

          I have a bash file that runs through and does all the steps I want it to. However, it moves some files and while the files are being moved the script goes back to the command prompt and it looks like nothing is happening with the script. How do I get it to wait until the files are moved then go on to the next step?
Question by:missymadi
    LVL 31

    Accepted Solution

    You can make it a background job like this:

    commands that take time &
    Then get the Process ID by doing


    wait $pid
    LVL 38

    Assisted Solution

    In the script, run the commands in sequence

    mv <source file> <target file>  (don't put it to background with &)
    <next command>
    LVL 31

    Expert Comment

    If you show the script, it would be easier to comment about it.
    LVL 48

    Expert Comment

    Simply don't run the move in the background.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
    How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    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

    24 Experts available now in Live!

    Get 1:1 Help Now