Sponsored Content
Top Forums Shell Programming and Scripting Shell to Python variable passing Post 302476682 by shashi792 on Thursday 2nd of December 2010 08:49:45 AM
Old 12-02-2010
Data 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
Code:
export X=12
echo "$("pwd")"
echo "$X"
exec python py.py "$(X)"

py.py
Code:
#!/usr/local/bin/python
import os
print "Now, we're going to add up some numbers."

if X < 100:
    print input("Total is not yet over 100, enter another number: ")
else:
    print ("That's it, you're done!")

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing value to shell variable

dear all How to passing the parameters or results to outside of the AWK program? anyone can help awk '{print $1}' file1 > $a ? (2 Replies)
Discussion started by: trynew
2 Replies

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

3. Shell Programming and Scripting

Passing shell variable to NAWK

I am trying to make a simple script in which i take input from shell and then forward the value to nawk (BEGIN). but when i run below mention script so it give no output. echo "Enter TRUNK GROUP:" read TGR cat /omp-data/logs/5etr/080422.APX | nawk -F"|" -v P=$TGR ' BEGIN { TG=P;... (1 Reply)
Discussion started by: wakhan
1 Replies

4. Shell Programming and Scripting

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 a=3 b=3; c= a+b exec python ofdm.py ofdm.py d=c+a Thanks in Anticipation (4 Replies)
Discussion started by: shashi792
4 Replies

5. UNIX for Dummies Questions & Answers

Passing a Shell Variable to awk

Hello, I have a file with 4 columns. An arbitrary example is shown below: a Tp 10 xyz b Tq 8 abc c Tp 99 pqr d Tp 44 rst e Tr 98 efg Based on the values in col 2 and col 3, I will execute another program. I have been running this:... (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

6. Shell Programming and Scripting

Passing Variable Parameters (C shell)

I am trying to execute a copy command via shell script. However, on occassion, 2 or more files need to copied. How do I code for the multiple arguments? Does it matter how the files are delimited? Example: I have a script to copy files from 1 dir to another called duplicate.csh In most... (1 Reply)
Discussion started by: CKT_newbie88
1 Replies

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

8. Shell Programming and Scripting

Passing a variable as input to another shell

I have a shell program that calls another shell program the following code works . chkTimeFormat.sh "10/9/12 17:51:19:783."|read c but when I am passing the the time in a variable like in the code below, the shell chkTimeFormat.sh is not returning proper value time="10/9/12... (9 Replies)
Discussion started by: swayam123
9 Replies

9. Shell Programming and Scripting

Passing values from awk to shell variable

I am writing a script where I need awk to test if two columns are the same and shell to do something if they are or are not. Here is the code I'm working with: @ test = 0 ... test = `awk '{if($1!=$2) print 1; else print 0}' time_test.tmp` #time_test.tmp holds two values separated by a space... (3 Replies)
Discussion started by: Malavin
3 Replies

10. UNIX for Dummies Questions & Answers

Passing Shell Variable to awk

Hello All, May i please why my shell variable is not getting passed into awk script. #!/bin/bash -vx i="1EB07C50" /bin/awk -v ID="$i" '/ID/ {match($0,/ID/);print substr($0,RSTART,RLENGTH)}' /var/log/ScriptLogs/keys.13556.txt Thank you. (1 Reply)
Discussion started by: Ariean
1 Replies
Algorithm::C3(3pm)					User Contributed Perl Documentation					Algorithm::C3(3pm)

NAME
Algorithm::C3 - A module for merging hierarchies using the C3 algorithm SYNOPSIS
use Algorithm::C3; # merging a classic diamond # inheritance graph like this: # # <A> # / # <B> <C> # / # <D> my @merged = Algorithm::C3::merge( 'D', sub { # extract the ISA array # from the package no strict 'refs'; @{$_[0] . '::ISA'}; } ); print join ", " => @merged; # prints D, B, C, A DESCRIPTION
This module implements the C3 algorithm. I have broken this out into it's own module because I found myself copying and pasting it way too often for various needs. Most of the uses I have for C3 revolve around class building and metamodels, but it could also be used for things like dependency resolution as well since it tends to do such a nice job of preserving local precedence orderings. Below is a brief explanation of C3 taken from the Class::C3 module. For more detailed information, see the "SEE ALSO" section and the links there. What is C3? C3 is the name of an algorithm which aims to provide a sane method resolution order under multiple inheritance. It was first introduced in the language Dylan (see links in the "SEE ALSO" section), and then later adopted as the preferred MRO (Method Resolution Order) for the new-style classes in Python 2.3. Most recently it has been adopted as the 'canonical' MRO for Perl 6 classes, and the default MRO for Parrot objects as well. How does C3 work. C3 works by always preserving local precedence ordering. This essentially means that no class will appear before any of it's subclasses. Take the classic diamond inheritance pattern for instance: <A> / <B> <C> / <D> The standard Perl 5 MRO would be (D, B, A, C). The result being that A appears before C, even though C is the subclass of A. The C3 MRO algorithm however, produces the following MRO (D, B, C, A), which does not have this same issue. This example is fairly trivial, for more complex examples and a deeper explanation, see the links in the "SEE ALSO" section. FUNCTION
merge ($root, $func_to_fetch_parent, $cache) This takes a $root node, which can be anything really it is up to you. Then it takes a $func_to_fetch_parent which can be either a CODE reference (see SYNOPSIS above for an example), or a string containing a method name to be called on all the items being linearized. An example of how this might look is below: { package A; sub supers { no strict 'refs'; @{$_[0] . '::ISA'}; } package C; our @ISA = ('A'); package B; our @ISA = ('A'); package D; our @ISA = ('B', 'C'); } print join ", " => Algorithm::C3::merge('D', 'supers'); The purpose of $func_to_fetch_parent is to provide a way for "merge" to extract the parents of $root. This is needed for C3 to be able to do it's work. The $cache parameter is an entirely optional performance measure, and should not change behavior. If supplied, it should be a hashref that merge can use as a private cache between runs to speed things up. Generally speaking, if you will be calling merge many times on related things, and the parent fetching function will return constant results given the same arguments during all of these calls, you can and should reuse the same shared cache hash for all of the calls. Example: sub do_some_merging { my %merge_cache; my @foo_mro = Algorithm::C3::Merge('Foo', &get_supers, \%merge_cache); my @bar_mro = Algorithm::C3::Merge('Bar', &get_supers, \%merge_cache); my @baz_mro = Algorithm::C3::Merge('Baz', &get_supers, \%merge_cache); my @quux_mro = Algorithm::C3::Merge('Quux', &get_supers, \%merge_cache); # ... } CODE COVERAGE
I use Devel::Cover to test the code coverage of my tests, below is the Devel::Cover report on this module's test suite. ------------------------ ------ ------ ------ ------ ------ ------ ------ File stmt bran cond sub pod time total ------------------------ ------ ------ ------ ------ ------ ------ ------ Algorithm/C3.pm 100.0 100.0 100.0 100.0 100.0 100.0 100.0 ------------------------ ------ ------ ------ ------ ------ ------ ------ Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 ------------------------ ------ ------ ------ ------ ------ ------ ------ SEE ALSO
The original Dylan paper <http://www.webcom.com/haahr/dylan/linearization-oopsla96.html> The prototype Perl 6 Object Model uses C3 <http://svn.openfoundry.org/pugs/perl5/Perl6-MetaModel/> Parrot now uses C3 <http://aspn.activestate.com/ASPN/Mail/Message/perl6-internals/2746631> <http://use.perl.org/~autrijus/journal/25768> Python 2.3 MRO related links <http://www.python.org/2.3/mro.html> <http://www.python.org/2.2.2/descrintro.html#mro> C3 for TinyCLOS <http://www.call-with-current-continuation.org/eggs/c3.html> AUTHORS
Stevan Little, <stevan@iinteractive.com> Brandon L. Black, <blblack@gmail.com> COPYRIGHT AND LICENSE
Copyright 2006 by Infinity Interactive, Inc. <http://www.iinteractive.com> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.0 2009-05-30 Algorithm::C3(3pm)
All times are GMT -4. The time now is 06:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy