Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All,

Following is my code;

echo "Enter time"
read fname1

sleep fname1 &

echo "have a nice day"


I need to sleep this process for such amount of time which taken from user (fname1) in background. when I try using above code it didn't execute properly. It skips the sleep and background.

Could you please help me to solve this.

Thank you.
Posted
Comments
Sergey Alexandrovich Kryukov 21-Oct-13 10:50am    
This is a wrong approach because you cannot guarantee that any particular amount of time, because OS is not a real-time one.
You can hope for help is you explain your purpose.
—SA

1 solution

The task sounds non-sense to me.
Running a process in background means:
the stell starts that command as background process (fire and forget) and immediately continues with the next command.

I.e. this completes instantly:
sleep 100 &
echo "done"


You may observe the sleep process by running the ps command.
Cheers
Andi

PS: In your case, the "in background" is non-sense. Leave away the &.
PPS: If you want the sleep and the echo go into one background process, do this:
read -p "Enter seconds: " sec; (sleep $sec; echo "have a nice day") &.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900