LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  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
#!/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...

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

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

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

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

Rep: Reputation: Disabled
Quote:
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 ?
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:46 AM.

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