Passing a variable as input to another shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing a variable as input to another shell
# 1  
Old 12-12-2012
Passing a variable as input to another shell

I have a shell program that calls another shell program

the following code works
Code:
. 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

Code:
time="10/9/12 17:51:19:783."
. chkTimeFormat.sh $time|read c

Please help
# 2  
Old 12-12-2012
Try using double quotes..

Code:
. chkTimeFormat.sh "$time"|read c

# 3  
Old 12-12-2012
Thanks but ,
Code:
. chkTimeFormat.sh "$time"|read c

it did not work.
Any more ideas...

Last edited by Franklin52; 12-12-2012 at 04:01 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 12-12-2012
What does not work? Pls be more specific, post output and/or error samples, variable contents, etc.
# 5  
Old 12-12-2012
Quote:
Originally Posted by swayam123
Thanks but ,
Code:
. chkTimeFormat.sh "$time"|read c

it did not work.
Any more ideas...
As Rudic said Please provide some details..

Please look how double quotes makes difference here.. Smilie

Code:
$ cat test2.sh
echo $1

$ . test2.sh "10/9/12 17:51:19:783."
10/9/12 17:51:19:783.

$ time="10/9/12 17:51:19:783."

$  . test2.sh $time
10/9/12

$ . test2.sh "$time"
10/9/12 17:51:19:783.

Hope this helps

pamu
# 6  
Old 12-12-2012
This the code for chkTimeFormat.sh is as follows
Code:
time=$1
var=$(echo "$time"|awk '{for(i=1;i<=NF;i++) if ( $i ~  /[0-2][0-9]:[0-5][0-9]:[0-5][0-9]/){print i}} ')

if [ $var -ge 0 ] 
then
 echo 1
else
 echo 0

fi

I called this script as follows from a different script n the following way
Code:
time="10/9/12 17:51:19:783."
. chkTimeFormat.sh $time|read c
echo $c

and

Code:
time="10/9/12 17:51:19:783."
. chkTimeFormat.sh "$time"|read c
echo $c

I was expecting and output
1
but I am getting
0

Please suggest
# 7  
Old 12-12-2012
Code:
 
c=$(. chkTimeFormat.sh "$time")
echo $c

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help on passing an input variable to the voronota program (after third pipe)

Dear UNIX forum members, I am using macbook pro 13 (2015 edition) with MAC OS Mojave and am trying to write the shell script where when it is run through terminal it asks for an input (in the code below an input variable is domains) and then that input becomes capital letter or letters which... (3 Replies)
Discussion started by: Aurimas
3 Replies

2. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

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

4. Shell Programming and Scripting

Passing variable as an input file to AWK comand

Hi, I would like to compare 2 files using awk, which I can do by using: awk 'NR==FNR{a;next} (NR > 32 && $2 in a) {print $0}' File1 and File2. If the name of the File1 is in another file (for example, column 4 in File 3) then how can I pass this column 4 to the awk command. Thanks in... (1 Reply)
Discussion started by: ezhil01
1 Replies

5. Shell Programming and Scripting

Passing string as a input parameter for a shell script

Hi i have a shell script which needs a string as an input parameter. How to pass the string param as an input? In command line am running the script. for e.g., a="who is a buddy?" sh sample.sh $a Inside the script i get this input param as $1 but only the value "who" is accepted... (12 Replies)
Discussion started by: vidhyaS
12 Replies

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

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

8. UNIX for Dummies Questions & Answers

Passing Shell Input to AWK

I am trying to search a log for a particluar pattern listing the total # of occurences in the end. I thought using a shell script for input then calling awk to search for the paramters specified. I want the script to be usable acorss envs. Code: #! /usr/bin/bash # get the variables... (5 Replies)
Discussion started by: wawa44oz
5 Replies

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

10. 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
Login or Register to Ask a Question