Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-26-2013, 03:33 AM   #1
shiv garg
LQ Newbie
Registered: Sep 2013
Location: Amritsar
Distribution: fedora 19
Posts: 11

Rep: Reputation: Disabled
sub shell problem in bash scripting

pls tell me how to return controll to parent process in bash scripting
my code was
while ((i<100))
while ((j<100))
`mkdir "shiv$i$j`
let j=j+1

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...

Last edited by shiv garg; 09-26-2013 at 03:34 AM.
Old 09-26-2013, 03:42 AM   #2
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
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).
Old 09-26-2013, 04:03 AM   #3
Senior Member
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
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

echo $DateAndTime
and you should really be using $()
echo $DateAndTime
for more details

on to your script,

for i in {000..100};do
    for j in {000..100};do
        mkdir "shiv_${i}_${j}"
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

Last edited by Firerat; 09-26-2013 at 04:10 AM. Reason: added link
Old 09-26-2013, 04:16 AM   #4
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 664

Rep: Reputation: 81
Originally Posted by shiv garg View Post
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 ?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell scripting help! computergeek7 Programming 2 04-27-2010 10:35 AM
Bash Shell Scripting help computergeek7 Programming 4 03-01-2010 06:33 PM
Bash Shell scripting help! computergeek7 Programming 2 03-01-2010 05:55 AM
Help with I/O on bash shell scripting Dave6383 Programming 1 06-03-2004 05:24 PM
BASH Shell scripting help ewarmour Linux - General 8 05-25-2002 07:10 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:31 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration