Arguments and suffix name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Arguments and suffix name
# 1  
Old 09-17-2010
Arguments and suffix name

While calling shell script i need to use prefix . Any idea?

Ex:
Code:
myscript.sh -parameter1 "AA;BB" -parameter2 "DD;E"


Last edited by radoulov; 09-17-2010 at 11:43 AM.. Reason: Code tags, please!
# 2  
Old 09-17-2010
try man getopt
This User Gave Thanks to Chirel For This Post:
# 3  
Old 09-17-2010
Code:
 # ./myscript.sh -parameter1 "AA;BB" -parameter2 "DD;E"
parametres are AA
parametres are BB
parametres are DD
parametres are E


Code:
# cat myscript.sh
 
#!/bin/bash
IFS=$';'
for i in $2 $4 ; do
echo -e parametres are "$i\n"
done
parametres are AA
parametres are BB
parametres are DD
parametres are E

This User Gave Thanks to ygemici For This Post:
# 4  
Old 09-17-2010
hi ygemici,
thanks ..Sorry i didn't explain clearly.. My batch is calling some java program and its taking 2 parameters.
There are 3 cases. It can be either one of these conditions
1)first parameter and second parameter are null
2)first parameter is not null and second parameter is null
3)first and second parameter are not null
################# Program###################
Code:
x=$1                                                            
y=$2                                                            

if [ "$1" ==  "" ] &&  [ "$2" == "" ] ; then
java -classpath $CLASSPATH  functionname
elif [ "$1" != "" ] && [ "$2" == "" ] ; then
java -classpath $CLASSPATH  functionname -parameter1 "$x"
elif [ "$1" != "" ] && [ "$2" != "" ] ; then
java -classpath $CLASSPATH  functionname -parameter1 "$x"  -parameter2 "$y"
fi

x can be AA;BB;CC or AA ...
##################################

while calling shell script manually i need to use prefix.
1)myscript.sh 2) myscript.sh -parameter1 value or 3) myscript.sh -paramerer1 value -paramter2 value

Last edited by Scott; 09-17-2010 at 12:44 PM.. Reason: Please use code tags
# 5  
Old 09-17-2010
hi mnjx

as far as i understand i try to write something Smilie
(for active run remove the echo in script Smilie )

we are a few tries for you i hope this is ok Smilie

Code:
[root@rhnserver ~]# ./myscript.sh
 -->   java -classpath yourjava/lib/class path functionname        <--

[root@rhnserver ~]# ./myscript.sh -t
 -->   java -classpath yourjava/lib/class path functionname        <--

[root@rhnserver ~]# ./myscript.sh -t 10
 -->   java -classpath yourjava/lib/class path functionname -t 10      <--

[root@rhnserver ~]# ./myscript.sh -t 10 -z
 -->   java -classpath yourjava/lib/class path functionname -t 10      <--

[root@rhnserver ~]# ./myscript.sh -t 10 -z 20
 -->   java -classpath yourjava/lib/class path functionname -t 10 -z 20    <--

Code:
# cat myscript.sh

#!/bin/bash

export CLASSPATH=$"yourjava/lib/class path"
frstparam="$1"
scndparam="$3"

 go () {
echo " -->   java -classpath $CLASSPATH functionname "$frstparam" $2 "$scndparam" $4    <-- "
}

 if [[ -z $2 ]] && [[ -z $4 ]] ; then
frstparam="" ; scndparam="" ; go ""
 elif [[ -z $4 ]] ; then
   scndparam="" ; go "$1" "$2"
 else
   go "$1" "$2" "$3" "$4"
 fi

regards
ygemici
This User Gave Thanks to ygemici For This Post:
# 6  
Old 09-21-2010
Ygemici,

Thank you so much.
Yes, this is what i want. I made small changes and its working fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Prefix/Suffix on same file

Hi, I want to add prefix and suffix on line# 205 using SED or AWK and want to change on the same file without creating new file. This command will be used in the bash script Am using Bash shell Regards Nayaj (3 Replies)
Discussion started by: Nayaj
3 Replies

2. Shell Programming and Scripting

Suffix formatting with awk

i would like to format the 9 character with suffix as "0". i tried below it doesn't work. >a=12345 > echo $a | awk '{printf "%-09s\n",$1}' >12345 required output is 123450000 can you guys help me out ? (7 Replies)
Discussion started by: expert
7 Replies

3. Shell Programming and Scripting

grep with two arguments to arguments to surch for

Hello, is it possible to give grep two documents to surche for? like grep "test" /home/one.txt AND /home/two.txt ? thanks (1 Reply)
Discussion started by: Cybertron
1 Replies

4. Shell Programming and Scripting

Replace prefix and suffix of a string

Hi, I'm new about shell scripting, and I need to do something like abcd **1234** efgh by abcd '''1234''' efgh I know that command sed helps about change one string by another, but I dont know how to keep whatever is inside **_** and replace * with '. Thanks! (5 Replies)
Discussion started by: selvaya
5 Replies

5. Shell Programming and Scripting

suffix a sequence in awk

hi I have a string pattern like ... ... 000446448742 00432265 040520100408 21974435 DEWSWATER GARRIER AAG IK4000 N 017500180000000000000000077000000000100 000446448742 00580937 040520100408 32083576 PEWSWATER BARRIER DAG GK4000 ... (6 Replies)
Discussion started by: zainravi
6 Replies

6. Shell Programming and Scripting

how to find files not suffix with .c

if I want to search those files which were suffix with .c, I can use find ./ -name *.c but how to find out those files which were not suffix with .c ?? Thanks a lot! (2 Replies)
Discussion started by: cqlouis
2 Replies

7. Shell Programming and Scripting

SED to add a suffix

Hi all, Im trying to make a proper hosts.allow with the lists of sshbl.org to block the ssh brute force attackers. The list is a text file with an IP on every line. What I've gotten up sofar is to prefix "sshd : " on every line, but I need a " : deny" suffix behind every line as well. ... (9 Replies)
Discussion started by: necron
9 Replies

8. Shell Programming and Scripting

File name suffix with a running number

Hi all, i have a shell script invoking a pl/sql proc which then, generates a file in a format DATA-26-12-2009.txt. The shell script is configured as a cron job to run once a day. If i need to run the script more than once, i need to suffix the generated file with a two digit running... (4 Replies)
Discussion started by: krishna.saran
4 Replies

9. Shell Programming and Scripting

csplit suffix-format: how to?

I am using GNU csplit to extract chapters from a big file into smaller files. I want to use the -b option -b, --suffix-format=FORMAT use sprintf FORMAT instead of %d but I have failed so far. 1) All the generated files need to have a suffix .txt at the end 2) They have to look like... (1 Reply)
Discussion started by: MarioColuzzi
1 Replies

10. Shell Programming and Scripting

prefix suffix to each argument

Hi, I have a variable, which contains comma separated values. Something like. StringA="abc,def,ghi,jkl" I want to apply prefix and suffix to each value in the string without using any loops. Say if Prefix is Pre_ and Suffix is _Suf then I need to get ... (1 Reply)
Discussion started by: tostay2003
1 Replies
Login or Register to Ask a Question