-1
#!/usr/bin/env bash
tt=0
one(){
    echo "Please enter some input: "
    read input_variable
    echo "You entered: $input_variable"
    tt=$input_variable
}
tho(){
    if $tt >0; then
    {
        for i in {1..100000}
        do
          echo $i $i
          sleep 2s
        done
    }
    fi
}
(one ; tho) &

This is just a small example of what I want to do. User takes time to give input and currently in the mean while tho() starts running. I want tho() to run after user has supplied the input variable, may it be after 2 days. Any suggestions would be great!

closed as unclear what you're asking by G-Man, Archemar, Michael Homer, Stephen Kitt, mdpc Aug 31 '16 at 23:25

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

2

The part that reads user input needs to run in the foreground. Only the foreground process can read from the terminal.

The syntax of your if condition doesn't make sense: $tt >0 runs the command whose name is in the variable tt¹ and redirects its output to a file called 0. To compare numbers, use the [ … ] syntax for conditional expressions or the ((…)) syntax for arithmetic expressions.

The braces in the if statement are useless: then … fi creates the same grouping already.

{1..100000} expands to 100000 words, then processes them one by one. To make a loop run 100000 times, use a loop counter.

Printing a line every 2 seconds makes no sense to me, but since I have no idea what you meant to do I'll leave it.

#!/bin/bash
one () {
    echo "Please enter some input: "
    read tt
    echo "You entered: $tt"
}
tho () {
    if [ "$tt" -gt 0 ]; then
        for ((i=0; i<=100000; i++)); do
          echo $i $i
          sleep 2s
        done
    fi
}
one
tho

If you want the tho part to run in the background, add & after tho.

¹ Approximately.

Not the answer you're looking for? Browse other questions tagged or ask your own question.