Passing variable from shell script to python script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Passing variable from shell script to python script

Shell Programming and Scripting


Tags
python, shell, variable

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-01-2010
shashi792 shashi792 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 2 December 2010, 9:25 AM EST
Posts: 35
Thanks: 8
Thanked 0 Times in 0 Posts
Error Passing variable from shell script to python script

I have a shell script main.sh which inturn call the python script ofdm.py, I want to pass two variables from shell script to python script for its execution. How do i achieve this ?????

Eg:

main.sh

Code:
a=3 b=3;
c= a+b
exec python ofdm.py

ofdm.py

Code:
d=c+a


Thanks in Anticipation
Sponsored Links
    #2  
Old 12-01-2010
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 1 October 2014, 9:32 AM EDT
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
Something like

Code:
exec python ofdm.py "$a" "$b"

?
Sponsored Links
    #3  
Old 12-01-2010
shashi792 shashi792 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 2 December 2010, 9:25 AM EST
Posts: 35
Thanks: 8
Thanked 0 Times in 0 Posts
The method is not working

below is my actual code.

Code:
export L=128

cd /home/betafish/Desktop/Cpp_codes/gnuradio/acoustic
echo "$("pwd")"
echo "$L"
exec python ofdm_acoustic.py "$L"

and the other python file is

Code:
#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: Ofdm Acoustic
# Generated: Wed Dec  1 18:17:52 2010
##################################################

from gnuradio import audio
from gnuradio import blks2
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.wxgui import constsink_gl
from gnuradio.wxgui import fftsink2
from grc_gnuradio import blks2 as grc_blks2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import wx

class ofdm_acoustic(grc_wxgui.top_block_gui):

	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Ofdm Acoustic")
		_icon_path = "/home/betafish/.local/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 32000

		##################################################
		# Blocks
		##################################################
		self.audio_sink_0 = audio.sink(48000, "", True)
		self.blks2_ofdm_demod_0 = grc_blks2.packet_demod_f(blks2.ofdm_demod(
				options=grc_blks2.options(
					modulation="qpsk",
					fft_length=512,
					occupied_tones=200,
					cp_length=[COLOR="rgb(255, 140, 0)"]L[/COLOR],
					snr=10,
					log=None,
					verbose=None,
				),
				callback=lambda ok, payload: self.blks2_ofdm_demod_0.recv_pkt(ok, payload),
			),
		)
		self.blks2_ofdm_mod_0 = grc_blks2.packet_mod_f(blks2.ofdm_mod(
				options=grc_blks2.options(
					modulation="qpsk",
					fft_length=512,
					occupied_tones=200,
					cp_length=L,
					pad_for_usrp=False,
					log=None,
					verbose=None,
				),
			),
			payload_length=0,
		)
		self.gr_complex_to_float_0 = gr.complex_to_float(1)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_float*1, samp_rate)
		self.gr_wavfile_sink_0 = gr.wavfile_sink("/home/betafish/Desktop/Cpp_codes/gnuradio/acoustic/data_rx", 1, samp_rate, 8)
		self.gr_wavfile_source_0 = gr.wavfile_source("/home/betafish/Desktop/Cpp_codes/gnuradio/acoustic/data_tx.wav", True)
		self.wxgui_constellationsink2_0 = constsink_gl.const_sink_c(
			self.GetWin(),
			title="Constellation Plot",
			sample_rate=samp_rate,
			frame_rate=5,
			const_size=2048,
			M=4,
			theta=0,
			alpha=0.005,
			fmax=0.06,
			mu=0.5,
			gain_mu=0.005,
			symbol_rate=samp_rate/4.,
			omega_limit=0.005,
		)
		self.Add(self.wxgui_constellationsink2_0.win)
		self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
			self.GetWin(),
			baseband_freq=9000,
			y_per_div=10,
			y_divs=10,
			ref_level=50,
			sample_rate=samp_rate,
			fft_size=1024,
			fft_rate=30,
			average=False,
			avg_alpha=None,
			title="FFT Plot",
			peak_hold=False,
		)
		self.Add(self.wxgui_fftsink2_0.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_wavfile_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.blks2_ofdm_mod_0, 0))
		self.connect((self.gr_complex_to_float_0, 0), (self.audio_sink_0, 0))
		self.connect((self.gr_complex_to_float_0, 1), (self.audio_sink_0, 1))
		self.connect((self.blks2_ofdm_mod_0, 0), (self.wxgui_fftsink2_0, 0))
		self.connect((self.blks2_ofdm_mod_0, 0), (self.wxgui_constellationsink2_0, 0))
		self.connect((self.blks2_ofdm_mod_0, 0), (self.gr_complex_to_float_0, 0))
		self.connect((self.blks2_ofdm_mod_0, 0), (self.blks2_ofdm_demod_0, 0))
		self.connect((self.blks2_ofdm_demod_0, 0), (self.gr_wavfile_sink_0, 0))

	def set_samp_rate(self, samp_rate):
		self.samp_rate = samp_rate
		self.wxgui_constellationsink2_0.set_sample_rate(self.samp_rate)
		self.wxgui_fftsink2_0.set_sample_rate(self.samp_rate)

if __name__ == '__main__':
	parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
	(options, args) = parser.parse_args()
	tb = ofdm_acoustic()
	tb.Run(True)

I have used L in spaces marked in red
    #4  
Old 12-01-2010
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 1 October 2014, 9:32 AM EDT
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts
is L gonna change ?
if not, then just go for

Code:
 exec python ofdm_acoustic.py 128

Sponsored Links
    #5  
Old 12-02-2010
shashi792 shashi792 is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 2 December 2010, 9:25 AM EST
Posts: 35
Thanks: 8
Thanked 0 Times in 0 Posts
L is obtained from another script (this changes everytime) from the previous script im using
Code:
export L

command to pass it between scripts

what should be done for changing L
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing a variable from shell script to mysql query? kero Shell Programming and Scripting 2 06-10-2009 01:37 PM
passing variables to python script darkphaux Web Programming 0 12-21-2008 02:52 AM
error in passing a variable to sqlplus from a shell script kripssmart Shell Programming and Scripting 3 07-08-2008 07:01 PM
Hi Python and shell script,the script hangs nathgopi214 Shell Programming and Scripting 0 03-19-2008 06:05 AM
passing awk variable to the shell script bcheaib Shell Programming and Scripting 3 07-21-2004 10:00 AM



All times are GMT -4. The time now is 06:26 AM.