Passing variable from shell script to python script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing variable from shell script to python script
# 1  
Old 12-01-2010
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
# 2  
Old 12-01-2010
Something like
Code:
exec python ofdm.py "$a" "$b"

?
# 3  
Old 12-01-2010
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
is L gonna change ?
if not, then just go for
Code:
 exec python ofdm_acoustic.py 128

# 5  
Old 12-02-2010
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing value of variable to a query within shell script

I have a script in which i connect to database to run a query and get the result of the query to a temp file. This works fine , now what i want is there is flat file which contains the value to be used in the query. I want to read this file line by line and then run the query for each value in that... (7 Replies)
Discussion started by: gpk_newbie
7 Replies

2. Shell Programming and Scripting

Passing shell variable to awk script

I want to pass a shell variable to awk script : # cat file PSAPSR3 3722000 91989.25 2 98 PSAPSR7 1562000 77000.1875 5 95 PSAPUNDO 92000 4087.5625 4 96 #... (8 Replies)
Discussion started by: Reboot
8 Replies

3. Shell Programming and Scripting

how to set/get shell env variable in python script

greetings, i have a sh script that calls a python script. the sh script sets an env variable BIN: export BIN=bin64i need to get that BIN variable's value and use it within this python script. anyone know how to do this? thanx in advance. (5 Replies)
Discussion started by: crimso
5 Replies

4. Shell Programming and Scripting

Issue with passing variable to Grep in a shell script

Hi, I'm trying to check if methods specified in a class have been added to the corrosponding interface. My code below is giving me the following errors: grep: function: No such file or directory grep: import($zipfile): No such file or directory grep: function: No such file or... (1 Reply)
Discussion started by: racshot65
1 Replies

5. Shell Programming and Scripting

Problem passing arguments to a Python script

I have part of the script below and I tried calling the script using ./tsimplex.py --fstmod=chris.cmod --nxz=8x6 --varp=0.25 but am getting the error option --fstmod must not have an argument Any idea on how to fix this would be highly appreciated #! /usr/bin/python import... (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

Shell to Python variable passing

Hi, I had to create a new thread as the old thread had to much of confusion I have two files shashi.sh and py.py I want to pass a variable from shashi.sh to py.py. How do i achieve that ?. shashi.sh export X=12 echo "$("pwd")" echo "$X" exec python py.py "$(X)" py.py... (0 Replies)
Discussion started by: shashi792
0 Replies

7. Shell Programming and Scripting

Passing a variable from shell script to mysql query?

I heard this was possible but from my research I haven't been able to figure it out yet. Seems it should be simple enough. Basically from a high level view I'm trying to accomplish... . $X='grep foo blah.log' then 'mysql command SELECT foo FROM bar WHERE ' . $X or something like that. ... (2 Replies)
Discussion started by: kero
2 Replies

8. Web Development

passing variables to python script

Hello again, You guys might remember me from the "Apache problems" thread. And because this forum is the only one that actually helped me out after months of problems I was hoping you could help me with something related. Now if you remember the final code that we made for creating an account... (0 Replies)
Discussion started by: darkphaux
0 Replies

9. Shell Programming and Scripting

error in passing a variable to sqlplus from a shell script

hi, I am using a shell script from where i will be conecting to sqlplus.. i am having a problem in passing a variable to sqlplus query.. i will be assigning the variable in the unix environment..whenever i am trying to pass a variable having the contents greater than 2500 characters, i am... (3 Replies)
Discussion started by: kripssmart
3 Replies

10. Shell Programming and Scripting

passing awk variable to the shell script

hi; i have a file containing lines like: 1|1069108123|96393669788|00963215755711|2|0|941||;serv:Pps6aSyria;first:0;bear i want to extract the second, third and fourth record of each line and store it in a file ";" seperated this is what i wrote while read line do ... (3 Replies)
Discussion started by: bcheaib
3 Replies
Login or Register to Ask a Question