Sponsored Content
Full Discussion: PERL $0 variable
Top Forums Shell Programming and Scripting PERL $0 variable Post 302904670 by Akshay Hegde on Thursday 5th of June 2014 02:25:15 PM
Old 06-05-2014
Code:
$ cat tester
#!/bin/bash

# scipt name
echo "script name  ${0##*/}"

# all arguments
echo "all arguments $*"

# argument count
echo "argument count $# "

# first argument
echo "First argument $1"

# second argument
echo "second argument $2"

# last argument
last=$#
echo "last argument ${!last}"

Code:
$ bash tester 1 2 3 4 

script name  tester
all arguments 1 2 3 4
argument count 4 
First argument 1
second argument 2
last argument 4

---------- Post updated at 12:55 AM ---------- Previous update was at 12:45 AM ----------

In case of perl

Code:
$ cat  test.pl
#!/usr/bin/perl
my $c = 1;
 
# script name
my $script = $0;

# count
my $argsc = $#ARGV + 1;
 
print "Total args passed to $script : $argsc \n";
 
# array @ARGV
foreach my $t(@ARGV) {
	print "Arg # $c : $t\n";
	$c++;
}

Code:
$ perl test.pl  1 2 3 4
Total args passed to test.pl : 4 
Arg # 1 : 1
Arg # 2 : 2
Arg # 3 : 3
Arg # 4 : 4

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl - variable inheritance

Hey Everyone, Does anyone know how - or if it's even possible - for a child perl script to inherit the variables of a parent perl script? In a shell script, you would use "export" for example. I am running Perl 5.8. Basically, let's say "perl1.pl" calls "perl2.pl" and I want "perl2.pl" to... (2 Replies)
Discussion started by: gsatch
2 Replies

2. Shell Programming and Scripting

perl not reading my variable

I'm trying to make changes in a file using the following bash script: #!/bin/bash MYHOME=`echo $HOME` README=$MYHOME"/environment" IAM=`whoami` CHANGEPATHLIST="TALOG TACONFIG TAINFO TAWORK TMPSPACE" for var in $CHANGEPATHLIST do perl -pi -e 's/sacuser1/$IAM/ if m/$var/' $README... (3 Replies)
Discussion started by: yoonixq4u
3 Replies

3. Shell Programming and Scripting

Multiple variable in a variable in Perl

Hi All, I am trying to convert the below Csh while loop into Perl while loop but the problem is that in this csh script, i have 2 variables inside a variable -> $count is a variable {SB$count} as a whole is another variable. Csh is able to assign values to such variable like the below but i do... (3 Replies)
Discussion started by: Raynon
3 Replies

4. Shell Programming and Scripting

perl get variable value ???

hi i have following code my $a1 = "A" ; my $a2 = "B" ; my $a3 = "C" ; foreach my $k ( 1,2,3 ) { my $msg = ${a{$k}} # this should be at runtime i am creating variable a1 and assigning it value to msg . print "$msg\n" ; } above thing is not working !!! i want when k = 1... (4 Replies)
Discussion started by: zedex
4 Replies

5. Shell Programming and Scripting

perl - how can we name a variable base on value of another variable

Hey all, perl - how can we name a variable base on the value of another variable? for example in ksh/bash we do : export c="100" export x`echo $c`=2000 echo $x100 x100=2000 is it possible to do something similar for perl? I already tried many ways but nothing is working. I am... (3 Replies)
Discussion started by: cacm1975
3 Replies

6. Shell Programming and Scripting

Perl variable declaration

what is the meaning of this particular line of code in perl. my %global_port2lanid = (); (2 Replies)
Discussion started by: suvenduperl
2 Replies

7. Shell Programming and Scripting

PERL : Use of a variable in a tr

Hi, I want to count the number of occurences of a character in a string variable ($str). The character is stored in a another variable ($sepchr). I am using tr as : $count = ($str =~ tr/$sepchr//); This did not work. I found in another thread about using eval. I used eval as : ... (13 Replies)
Discussion started by: sinpeak
13 Replies

8. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

9. Shell Programming and Scripting

how to declare variable in perl

how can i declare variable in perl. for BLOCK in /sys/block/emcpow* (3 Replies)
Discussion started by: learnbash
3 Replies

10. Shell Programming and Scripting

Perl help - how to assign output of perl to variable

Hi, guys, i have a script i inherited from a coworker but i'm not perl savy. The script works but i would like it to work better. I want to run this command ./ciscomgrtest.pl -r "show version" -h hosts.router and have the script goto each router in the hosts.router file and run the command... (2 Replies)
Discussion started by: whipuras
2 Replies
GCHEM3D(1)						       gnome-chemistry-utils							GCHEM3D(1)

NAME
gchem3d - a small chemical viewer application SYNOPSIS
gchem3d [OPTION(S)...] [FILE...] DESCRIPTION
gchem3d is a small chemical viewer application, which can show several chemical file formats. OPTIONS
The following options are accepted: -b COLOR, --bgcolor=COLOR Use the given color as background color. COLOR can be one of "black" (default), "white", "#rrggbb" (don't forget to escape the "#" character in the shell). -d MODEL, --display3d=MODEL Choose how molecules are displayed. MODEL can be one of "BallnStick" (default), "SpaceFill". -?, --help Show application help options. --help-all, --help-* Print all or just a group of help options. These options are not documented here. Instead see gtk-options(7) and gnome-options(7). -v, --version Print gchem3d version information. SEE ALSO
gnome-options(7), gtk-options(7) AUTHORS
Jean Brefort <jean.brefort@normalesup.org> Program author. Daniel Leidert <daniel.leidert@wgdd.de> Manpage author. COPYRIGHT
Copyright (C) 2002-2007 Jean Brefort Copyright (C) 2004-2007 Daniel Leidert Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation. gcu 0.12 $Date: 2009-03-19 10:53:47 +0100 (jeu. 19 mars 2009) $ GCHEM3D(1)
All times are GMT -4. The time now is 08:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy