LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-07-2005, 08:08 AM   #1
karunesh
Member
 
Registered: Jan 2002
Location: India
Distribution: CentOS/Mandriva
Posts: 126

Rep: Reputation: 15
Question Command & Variable


Hi Folks.

I am trying to write a shell script, in that I am reading some iptables commands in a variable form some txt file. Now I want to execute those commands using shell script. So here I am confused, how to do that !!

Can anyone help !
 
Old 04-07-2005, 09:23 AM   #2
mcosta
Member
 
Registered: Jan 2005
Location: Spain
Distribution: Debian
Posts: 44

Rep: Reputation: 16
SOME_COMMAND="echo this is a command"
$SOME_COMMAND
SOME_PARAMETERS="whatever you want"
echo $SOME_PARAMETERS

are you talking of that?
 
Old 04-07-2005, 01:42 PM   #3
sirclif
Member
 
Registered: Sep 2004
Location: south texas
Distribution: fedora core 3,4; gentoo
Posts: 192

Rep: Reputation: 30
if you have a string variable that is a command such as:

var="echo 'hello world'"

then you can execute the command represented by the string with exec

exec $var
 
Old 04-08-2005, 05:19 AM   #4
mcosta
Member
 
Registered: Jan 2005
Location: Spain
Distribution: Debian
Posts: 44

Rep: Reputation: 16
Quote:
Originally posted by sirclif
if you have a string variable that is a command such as:

var="echo 'hello world'"

then you can execute the command represented by the string with exec

exec $var
You are right, but doing so never goes back to the script, I mean:
[CODE]
var="echo 'hello world'"
exec $var
echo bye world
[CODE]
Does not executes the 'echo bye world'. 'exec' does not fork, it replaces the shell with the command.
 
Old 04-08-2005, 05:53 AM   #5
rajniks
LQ Newbie
 
Registered: Mar 2005
Location: India
Distribution: FC3
Posts: 3

Rep: Reputation: 0
yup forking is one of the way of doing it .the parent process can fork() a child process...........i am also new to linux so dont know how exctlly to make that funcyion call.............but can be tried on that way.......................i will try doing it and post a reply later
 
Old 04-08-2005, 06:54 PM   #6
mcosta
Member
 
Registered: Jan 2005
Location: Spain
Distribution: Debian
Posts: 44

Rep: Reputation: 16
fork() is in c. In shell script there is no equivalent. I mean, when calling a comand, internally, bash makes fork+exec. But if you do 'exec command', only exec is called. So there is no more shell process, only the 'command' process.
 
  


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
buffer/cache variable for free command... audibel Linux - Software 3 12-14-2007 02:54 PM
How to set PATH variable for command tracert? princegbenga Linux - Software 2 06-14-2007 07:48 AM
Bash script; command and args in variable. magjo813 Programming 2 02-16-2004 09:22 AM
Assigning the output of one command to a variable (shell) guru_stew Programming 5 08-03-2003 06:12 PM
How do I pass a C variable to a Bash command ? Linh Programming 6 07-07-2003 03:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:33 PM.

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