How to use perl to run bash with argument?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use perl to run bash with argument?
# 1  
Old 07-12-2010
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.

Code:
#! /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
Code:
#!/bin/bash
funct(){
    ntad=$1 
    smad=$2
    rtad=$3
    domain=$4
    dns=$5
    
    echo "ntad is $ntad"
    echo "smad is $smad"
    echo "rtad is $rtad"
    echo "domain is $domain"
    echo "dns are $dns"
}

if [ $# -ge 5 ];then
    funct $@
else
    echo "The number of Arguments is less then 5."
    echo $#
fi

exit 0


when i run it,
it says

Code:
bash-3.00# ls
bin          config       etc          expected     lib          log          runtest.pl   testdir      testscripts  tmp
bash-3.00# pwd
/eweiquu/ocsta
bash-3.00# ./runtest.pl
./eweiquu/ocsta/testdir/ft_623.sh 3 4 5 6 7Can't exec "./eweiquu/ocsta/testdir/ft_623.sh": No such file or directory at ./runtest.pl line 8.
bash-3.00# cd runtest.pl
bash: cd: runtest.pl: Not a directory
bash-3.00# cd testdir/
bash-3.00# ls
ft_621.sh  ft_623.sh
bash-3.00# pwd
/eweiquu/ocsta/testdir

and if I modify the perl cmd
Code:
my $cmd="bash $root/testdir/ft_623.sh 3 4 5 6 7";

it works properly

but sometimes the script is not written by the bash
I just want to use dot(.) to run the script

what can i do?


BRs
Damon sine

---------- Post updated at 01:02 PM ---------- Previous update was at 12:32 PM ----------

and if I write like this
Code:
my $cmd=". $root/testdir/ft_623.sh 3 4 5 6 7";

it says
Code:
bash-3.00# ./runtest.pl
. /eweiquu/ocsta/testdir/ft_623.sh 3 4 5 6 7\nThe number of Arguments is less then 5.
0


Last edited by Damon sine; 07-12-2010 at 03:12 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

3. Shell Programming and Scripting

How to send to perl 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#!/bin/bash export RECEIVEDDATE=$(date +"%Y%m%d.%H%M%S") perl checkdate.py checkdate.pyimport datetime import os... (3 Replies)
Discussion started by: Tribe
3 Replies

4. Shell Programming and Scripting

Pass argument in script to run specific part in that

Hello Friends, I need you help ! I have a scripts names runsteps.sh which contains command to run bunch of commands for each application you want to install " Oracle " Jboss" etc echo " Which app you want to install Jboss" ? Yes or no? read ans depending on Yes or not it goes inside... (3 Replies)
Discussion started by: saurabh84g
3 Replies

5. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

6. Shell Programming and Scripting

Perl script run a bash script

Hi All, I think the processing of this is much more complex, so I will explain the whole process by codes. First,I wrote a expect script named bsim.exp as follows: #! /usr/local/bin/expect set command set name eval spawn $command switch -exact $command { "bash expecttest.sh" { ... (2 Replies)
Discussion started by: Damon sine
2 Replies

7. Shell Programming and Scripting

Using GET, passing argument to bash

Hi guys! So, I use GET ( Simple user agent using LWP library. ) on a remote text file that is then passed to bash and executed. However, I need to pass that bash script a single argument, and so far nothing that I have tried has worked, although I have learned quite a bit about input/output... (5 Replies)
Discussion started by: Rhije
5 Replies

8. Shell Programming and Scripting

Need to run the script by argument passing

Hi All, I have a question regarding running this script by passing an argument, for example ./ShellParse.sh sun, how do i do that? So i want when i pass argument sun, it shouild execute things inside the for loop. I want to support some other platforms too, so there are more for loops to... (3 Replies)
Discussion started by: asirohi
3 Replies

9. Shell Programming and Scripting

Run with argument

I have created shell script to run sql query something like below. i can use this script with only few arguments. But how can i modify the script if empno is huge in numbers. For example ./script.ksh 1234 select * from emp where empno in $1 (2 Replies)
Discussion started by: ford2020
2 Replies

10. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies
Login or Register to Ask a Question