Sponsored Content
Top Forums Shell Programming and Scripting printing last argument in shell script Post 302091559 by petebear on Tuesday 3rd of October 2006 03:26:19 PM
Old 10-03-2006
With bash version 3.0 or higher you can use
Code:
${BASH_ARGV[0]}

This little explanation is of courtesy Dark_Helmet over at linxquestions.org
Quote:
BASH_ARGV is a special built-in variable. It's an array of the command line arguments. More specifically, the man page says it's the arguments located on the stack. So it's safe to read them, but I strongly suggest not modifying them. To access the array, use [X] to refer to a specific argument. The arguments are put on the stack "backwards" and explains why the last argument is indexed with 0. Lastly, BASH_ARGV will change inside a function call (because the stack changes). So be careful where/how you access the variable.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script argument parsing

how to parse the command line argument to look for '@' sign and the following with '.'. In my shell script one of the argument passed is email address. I want to parse this email address to look for correct format. rmjoe123@hotmail.com has '@' sign and followed by a '.' to be more... (1 Reply)
Discussion started by: rmjoe
1 Replies

2. Shell Programming and Scripting

Problem when passing argument to a shell script

Hi all, I'm new to Shell scripting. In my shell script for Bourne shell, the script accepts a date parameter which is optional. If the value is supplied, the supplied value should be assigned to a variable. If not, the current date will be assigned to the variable. My script is like this. #!... (9 Replies)
Discussion started by: sumesh.abraham
9 Replies

3. UNIX for Dummies Questions & Answers

Shell script $0 argument

Hi, If not running a shell script file in current shell (. ./fileName) then $0 represents the executable file name. But in case of invoking shell script file in current shell then i m getting "$0 as -bash" . In such case how can i get the program name (running shell script file name)? Thanks, (2 Replies)
Discussion started by: painulyarun
2 Replies

4. Shell Programming and Scripting

Argument in shell script never blank

Hi All, I have a script which accepts a parameter which can either be blank, a specific value, or a wildcard value. But it never seems to be blank and the wildcard option seems to return the names of matching files in my directory. This happens even with the worlds simplest script that just... (1 Reply)
Discussion started by: cdines
1 Replies

5. Shell Programming and Scripting

Passing argument from Java to Shell script

Hi All, I want to pass array of argument from Java to a shell script.I can use process builder api and its exec() method to call the script,but the question is how to receive the parameter in the script. Thanks in advance ---------- Post updated at 10:00 PM ---------- Previous update was... (1 Reply)
Discussion started by: Abhijeet_Atti
1 Replies

6. Shell Programming and Scripting

How we can pass the argument when calling shell script from perl script

Can someone let me know how could I achieve this In one of per script I am calling the shell script but I need to so one thing that is one shell script call I need to pass pne argument.In below code I am calling my ftp script but here I want to pass one argument so how could I do this (e.g:... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

7. Shell Programming and Scripting

Shell script to find the sum of argument passed to the script

I want to make a script which takes the number of argument, add those argument and gives output to the user, but I am not getting through... Script that i am using is below : #!/bin/bash sum=0 for i in $@ do sum=$sum+$1 echo $sum shift done I am executing the script as... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

8. Shell Programming and Scripting

Help with Handling multiple argument in shell script

Hi i have written a shell script that takes only single ip address from the user and calculates its latency and reliability, can you please tell me that what should be done if i want that user should enter 100 or 1000 ip address (5 Replies)
Discussion started by: Preeti_17
5 Replies

9. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

10. Shell Programming and Scripting

Getting number of argument passed to a shell script

Hi Experts, I have been trying to work on a simple shell script that will just add the two argument passed to it. Here is what i tried : #!/bin/bash welcome(){ echo "Welcome to this Progg. which will accept two parameter" } main_logic(){ arg=$# echo "Number of argument passed is... (4 Replies)
Discussion started by: mukulverma2408
4 Replies
ALLOCA(3)						     Linux Programmer's Manual							 ALLOCA(3)

NAME
alloca - allocate memory that is automatically freed SYNOPSIS
#include <alloca.h> void *alloca(size_t size); DESCRIPTION
The alloca() function allocates size bytes of space in the stack frame of the caller. This temporary space is automatically freed when the function that called alloca() returns to its caller. RETURN VALUE
The alloca() function returns a pointer to the beginning of the allocated space. If the allocation causes stack overflow, program behavior is undefined. CONFORMING TO
This function is not in POSIX.1-2001. There is evidence that the alloca() function appeared in 32V, PWB, PWB.2, 3BSD, and 4BSD. There is a man page for it in 4.3BSD. Linux uses the GNU version. NOTES
The alloca() function is machine- and compiler-dependent. For certain applications, its use can improve efficiency compared to the use of malloc(3) plus free(3). In certain cases, it can also simplify memory deallocation in applications that use longjmp(3) or siglongjmp(3). Otherwise, its use is discouraged. Because the space allocated by alloca() is allocated within the stack frame, that space is automatically freed if the function return is jumped over by a call to longjmp(3) or siglongjmp(3). Do not attempt to free(3) space allocated by alloca()! Notes on the GNU Version Normally, gcc(1) translates calls to alloca() with inlined code. This is not done when either the -ansi, -std=c89, -std=c99, or the -fno-builtin option is given (and the header <alloca.h> is not included). But beware! By default the glibc version of <stdlib.h> includes <alloca.h> and that contains the line: #define alloca(size) __builtin_alloca (size) with messy consequences if one has a private version of this function. The fact that the code is inlined means that it is impossible to take the address of this function, or to change its behavior by linking with a different library. The inlined code often consists of a single instruction adjusting the stack pointer, and does not check for stack overflow. Thus, there is no NULL error return. BUGS
There is no error indication if the stack frame cannot be extended. (However, after a failed allocation, the program is likely to receive a SIGSEGV signal if it attempts to access the unallocated space.) On many systems alloca() cannot be used inside the list of arguments of a function call, because the stack space reserved by alloca() would appear on the stack in the middle of the space for the function arguments. SEE ALSO
brk(2), longjmp(3), malloc(3) COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2008-01-24 ALLOCA(3)
All times are GMT -4. The time now is 12:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy