LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sub shell problem in bash scripting (https://www.linuxquestions.org/questions/linux-newbie-8/sub-shell-problem-in-bash-scripting-4175478604/)

shiv garg 09-26-2013 03:33 AM

sub shell problem in bash scripting
 
pls tell me how to return controll to parent process in bash scripting
my code was
#!/bin/bash
global_i=0
global_j=0
while ((i<100))
do
(
while ((j<100))
do
`mkdir "shiv$i$j`
let j=j+1
done
)
i=i+1
done



when i ran this script every thing was working fine i mean to say that 100*100 folders were making in the folder in which script is running...

but the problem is that when i check for pid from other terminal there are only two processes one for parent process and other is of subshell... but i do wanna 100 sub shells... how to do this pls help me...

druuna 09-26-2013 03:42 AM

Can you tell us what your overall goal is?

The `mkdir "shiv$i$j` part is executed one at the time. There will only be 2 shells (the script itself and the mkdir sub-shell) at the time.

The back-ticks aren't needed for this script to make it work. But then again, maybe you want to accomplish something that isn't clear (to me).

Firerat 09-26-2013 04:03 AM

going off your two posts you seem to be confused with what the backticks are actually for

often they are used to 'capture' the output of a command
for example, to 'store' the date

Code:

DateAndTime=`date`
echo $DateAndTime

and you should really be using $()
Code:

DateAndTime=$(date)
echo $DateAndTime

see http://tldp.org/LDP/abs/html/commandsub.html
for more details


on to your script,

Code:

#!/bin/bash
for i in {000..100};do
    for j in {000..100};do
        mkdir "shiv_${i}_${j}"
    done
done

when working with numbers in {dir,file}names I like to 'pad' with 0s, makes a listing much easier to read/process
the use of {} in ${i} ${j} allows for the _, example shiv$i_$j would give shiv_001 , since $i_ does not exist

SAbhi 09-26-2013 04:16 AM

Quote:

Originally Posted by shiv garg (Post 5035059)
but i do wanna 100 sub shells... how to do this pls help me...

All other things covered above so the remaining is "Why you want your system to be loaded with child processes just for the same task to be performed everytime ?" People try to make things simpler with scripts and you are asking to make it more messy..

Either you are confused in how the control works or you should tell us what you are exactly trying to do ?


All times are GMT -5. The time now is 08:52 AM.