parameter identification problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parameter identification problem
# 1  
Old 03-12-2011
parameter identification problem

Hello everyone

suppose i have a script which can take any no. of parameters and in any order then how can i identify a particular parameter at which position it is entered

suppose

i call a script with four parameter

Code:
./abc.sh a b c d 
 
in above calling 
a is called at no. 1 position
b is at no 2 
c is at no 3 
d is at no 4


how can i this identify position of parameter in script

hope i have explained my question

Last edited by radoulov; 03-12-2011 at 05:33 AM.. Reason: Code tags, please!
# 2  
Old 03-12-2011
What exactly do you want to achieve (why do you think you need to know the position)?
# 3  
Old 03-12-2011
Code:
pos=1
for arg in "$@"
do
if [[ ${arg} == "-st" ]]
then
echo "abc"
echo ${pos}
parameter=$((${pos}+1))
echo $parameter
        if [[ $parameter == "" ]]
                then
                        echo "please enter date"
                fi
fi
pos=$((${pos}+1))
done
~
~
 
 
./abc.sh a b c -st 
 
then output is 
abc
4
5

 
y it is not printing the "please enter date as i have not entered fifth positional parameter"

# 4  
Old 03-12-2011
Still cannot understand what you want to achieve but if you change your if condition
FROM
Code:
 if [[ $parameter == "" ]]

TO
Code:
if [[ $pos == $# ]]

it will ask you please enter date
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Problem with STL's std::set container parameter to the operator << ()

Hi, I have this following code which gives me error when compiling. The problem is happening at the point where I create a const_iterator inside the overloaded insertion operator (i.e) operator << () function. The template argument version of set is not correct I guess. Could anyone please pitch... (3 Replies)
Discussion started by: royalibrahim
3 Replies

2. AIX

Audit problem : A system call received a parameter that is not valid.

while i try to start the audit i have the below error message . audit>audit start ** auditing enabled already A system call received a parameter that is not valid. please advice (6 Replies)
Discussion started by: thecobra151
6 Replies

3. Shell Programming and Scripting

file identification

hi there, i have written the following simple lines: find $SCENE -name "*.xml" echo -n "Input the name of the image file to be read: " set im_name = ($<) i like to set the value for im_name automatically to the .xml, which was found by the first line without having to input it. the... (4 Replies)
Discussion started by: friend
4 Replies

4. Shell Programming and Scripting

Parameter Passing problem

Hi All, I developed a KSH script which will accept two parameters as input. These two parameters are some directories paths. In the script i am validating the number of paramaters it received as below #-------------------------------------- # Check Command line arguments... (8 Replies)
Discussion started by: Raamc
8 Replies

5. Shell Programming and Scripting

Problem if parameter has space in it using loop

for cmdopts in $*;do case $cmdopts in -mode) mode="$2";shift 2 ;; -server) server="$2";shift 2 ;; -Id) Id="$2";shift 2 ;; -passwd) passwd="$2";shift 2 ;; -rmtDir) rmtDir="$2";shift 2 ;; -lcDir) ... (9 Replies)
Discussion started by: pinnacle
9 Replies

6. UNIX for Dummies Questions & Answers

file identification

Can anybody tell me what are these files are and what do they do and if they are safe to delete. Thanks /var/cache/yum/base # ls -al total 44792 drwxr-xr-x 4 root root 4096 Sep 22 11:43 . drwxr-xr-x 10 root root 4096 Nov 18 2007 .. -rw-r--r-- 1 root root 0 Sep 22... (5 Replies)
Discussion started by: mcraul
5 Replies

7. UNIX for Dummies Questions & Answers

ip identification

how can i find my own ip address from unix. command like who -x .this would provide all the ip address but i need to list only current user ip address. who am i command does not display the ip. (1 Reply)
Discussion started by: naushad
1 Replies

8. Shell Programming and Scripting

Parameter Problem With an Array Variable

Hi, I have two bash shell scripts: test: rrdhcp78-120:test_data msb65$ cat ~/bin/test #!/bin/sh array1=() echo 'elements in array1:' ${#array1} ~/bin/test2 $array1 test2: rrdhcp78-120:test_data msb65$ cat ~/bin/test2 #!/bin/sh array2=${1} (5 Replies)
Discussion started by: msb65
5 Replies

9. Shell Programming and Scripting

Parameter problem in my script

Hi all I hope that any one help me with my small problem :) My problem is: inside my script their is a parameter x=example.tar.Z I want to write a script to let y=example (without .tar.Z) Thank you in advanced :) (11 Replies)
Discussion started by: Laibro
11 Replies

10. Shell Programming and Scripting

version identification

Hi Which command do i use to know which version of solaris am i working on?? thanks in advance regards (1 Reply)
Discussion started by: knopix
1 Replies
Login or Register to Ask a Question