How to send to perl the content of a bash variable as argument?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to send to perl the content of a bash variable as argument?
# 1  
Old 11-22-2015
How to send to python the content of a bash variable as argument?

I want to send the content of a bash variable as a python argument for processing. The problem is that bash doesn't "expand" the content, just sends the expression.

script.sh
Code:
#!/bin/bash
export RECEIVEDDATE=$(date +"%Y%m%d.%H%M%S")
perl checkdate.py


checkdate.py
Code:
import datetime
import os
import sys
start_date = str(sys.argv[1])
date_1 = datetime.datetime.strptime(start_date, "%Y%m%d.%H%M%S")
# Operate with date_1

Code:
bash script.sh


Last edited by Tribe; 11-23-2015 at 04:25 AM..
# 2  
Old 11-22-2015
I admit I am a little perplexed. Smilie

Why are you trying to call a Python script invoking it with the binary perl?
How do you know that Bash is not expanding and exporting RECEIVEDDATE?
Code:
export RECEIVEDDATE=$(date +"%Y%m%d.%H%M%S")

I'll say it is the only thing working there.
# 3  
Old 11-23-2015
Guessing that RECEIVEDDATE is the variable that you want to be handed over to / processed by the script, I can't see that neither supplied as a parameter to nor referenced within the script.
# 4  
Old 11-23-2015
Quote:
Originally Posted by Aia
I admit I am a little perplexed. Smilie

Why are you trying to call a Python script invoking it with the binary perl?
How do you know that Bash is not expanding and exporting RECEIVEDDATE?
Code:
export RECEIVEDDATE=$(date +"%Y%m%d.%H%M%S")

I'll say it is the only thing working there.
My mistake. It's python, not perl. I wrote incorrectly the thread title.


Quote:
Originally Posted by RudiC
Guessing that RECEIVEDDATE is the variable that you want to be handed over to / processed by the script, I can't see that neither supplied as a parameter to nor referenced within the script.
It doesn't matter because we are passing by value, not by reference, which is what @Aia suggests (reading from environment variable). I don't like that way because reading from environment variable is broken in some verison of python, so I prefer passing by value.

Anyway it's solved, because the problem was in the PTY communication. Changing the terminal solved the issue, so it's working properly as expected (bash replaces $RECEIVEDDATE with its contents before sending it as argument to perl).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Send file content in mail

Hi . I am new to scripting.I am trying to mail the recent file contents but not the below script which i wrote is not working.Please guide me in finishing the script File='find /Directory path/*.fnr | tail -1' content=' cat $File' echo $content | mail -s "Subject " "myname@company.com" ... (7 Replies)
Discussion started by: karthik771
7 Replies

2. Shell Programming and Scripting

Passing variable from bash to perl script

Hi All, I need to pass a variable from bash script to perl script and in the perl script i am using those variables in the sql query but its giving error : Use of uninitialized value $ENV{"COUNTRYCD"} in concatenation (.) or string at /GIS_ROOT/custom/tables/DBread_vendor.pl line 50. Can ... (6 Replies)
Discussion started by: NileshJ
6 Replies

3. Shell Programming and Scripting

How to change Linux Terminal environment variable in a perl or bash script?

Hi, I meet an problem that it cannot change Terminal environment variable in a perl or bash script. This change can only exist and become effective in script lifetime. But I want to make this change take effect in current opened Terminal. In our view, the thought seems to be impossible, As... (9 Replies)
Discussion started by: weichanghe2000
9 Replies

4. Shell Programming and Scripting

Adding Content to Variable (bash)

is this possible? its kind of like incrementing the value of a number in a variable. but in this case, instead of the value of the variable being a number, it's just contents/strings/characters/alpha-numeric etc. NOT a number. For instance: VAR=Tommy for all in $(blah blah) do ... (2 Replies)
Discussion started by: SkySmart
2 Replies

5. Shell Programming and Scripting

bash: How to send a file/directory as argument?

Hi, I'd like to make a script where I can send a directory OR files as an argument, and compress them. My proble mis, I do know how to send a directory, but I do not know what to do if there are more than 1 file, I mean I can store the directory in $1, but how do I store 4 files? must I write $1,... (3 Replies)
Discussion started by: lamachejo
3 Replies

6. Shell Programming and Scripting

How to use perl to run bash with argument?

Hi All, I want to run a bash script using perl. But they are in the different dir. #! /usr/bin/perl -w use strict; my $root=`pwd`; chomp($root); my $cmd=".$root/testdir/ft_623.sh 3 4 5 6 7"; print $cmd; my @line=`$cmd`; foreach (@line){ print $_; } ft_623.sh (0 Replies)
Discussion started by: Damon sine
0 Replies

7. Shell Programming and Scripting

Bash : Check aphanumeric content in variable

Hello everyone, I'm trying the best way to implement a check on a variable ... in particular I need to assess the content of characters and numbers , I tried on various manuals bash scripting but I could not figure out how to do ... any help? (3 Replies)
Discussion started by: ionral
3 Replies

8. Shell Programming and Scripting

how to send an email with some body content and attachment

hi plz help me in sending a mail with some data in body and an attachment as some txt file. currently i am able to send mail with some body content, i need an example how to send the same along with attachment. thanks in advance -bali (2 Replies)
Discussion started by: balireddy_77
2 Replies

9. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies

10. UNIX for Dummies Questions & Answers

To send an email with the body content extracted from a file

Hi, I have been trying to shoot an email with the email body to be obtained from a file. Can someone please help me with it.. I have been trying to use the MAILX commad for the same. mailx -s "test email" -r sender@test.com < file.txt but it sends the file as an attachment,while i... (3 Replies)
Discussion started by: rohit.shetty84
3 Replies
Login or Register to Ask a Question