key word parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting key word parameter
# 1  
Old 12-03-2009
key word parameter

Code:
cat shell_script.ksh
x=$A
y=$B
export x
export y
echo $x
echo $y

when i am running this with a command
Code:
ksh shell_script.ksh -A 10 -B 20

its not showing anything ....
could you let me know how i can use key word type paramter

Last edited by zaxxon; 12-03-2009 at 05:02 AM.. Reason: code tags
# 2  
Old 12-03-2009
Not sure what you are trying to achieve, you could use positional shell parameters which are $1, $2, ... or getopts for example to use parameters like -A -B and so on.
You should only export variables if you want to use them in you environment for further usage.
For just echoing them it is not needed to export them at all.
Instead calling a ksh which executes the script, you can use a shebang in the 1st line of your script to make sure a ksh is being used like (change the path to where your ksh is located):
Code:
#!/usr/bin/ksh
...

Maybe you are ok with something like:
Code:
#!/usr/bin/ksh

x=$1
y=$2

echo $x
echo $y

exit 0

Calling this with
Code:
./myscript.ksh 10 20
10
20

If x and y is not needed you directly print out $1 and $2.
# 3  
Old 12-03-2009
Something like:

Code:
while getopts A:B: ARG; do
  case "$ARG" in
    A)  x=$OPTARG;;
    B)  y=$OPTARG;;
  esac
done

echo $x
echo $y


./Test.ksh -A 10 -B 20
10
20

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to Grep second word in config file using parameter?

Currently i am building one script to grep region records in the config file based on parameter and then i am creating a text file with that out put and i am reading the source file path in that out put file now i need to pass one more parameter like module based upon that it has to create a... (1 Reply)
Discussion started by: saranath
1 Replies

2. Shell Programming and Scripting

How do i replace a word ending with "key" using awk excpet for one word?

echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} | awk 'gsub(/^|abc,|$/,"") {print}' Required output {grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies

3. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

4. Homework & Coursework Questions

Tru to print the last name and first name using key word

I am new to shell scripting and trying to do the below Stan:Smith:Detroit:MI Jim:Jones:Farmington Hills:MI Jack:Frost:Denver:CO Sue:Apple:New York:NY Cindy:Thompson:Battle Creek:MI John:Smith:Denver:CO George:Jones:New York:NY Need to create a shell script This script will display the... (1 Reply)
Discussion started by: jakemathew
1 Replies

5. Shell Programming and Scripting

How to pass two word parameter

Hi, How to pass parameter to run folloing script? #parameters are div, dept, style U run_convert_pdm.ksh Mens 44 7542 U run_convert_pdm.ksh "Mens Knit" 44 7541 The first command works fine but the second needs to have two words together , it does not work even if I have used double... (15 Replies)
Discussion started by: sandy162
15 Replies

6. Shell Programming and Scripting

print lines from a file containing key word

i have a file containing over 1 million records,and i want to print about 300,000 line containing a some specific words. file has content. eg 1,rrt,234 3,fgt,678 4,crf,456 5,cde,drt 6,cfg,123 and i want to print the line with the word fgt,crf this is just an example,my file is so... (2 Replies)
Discussion started by: tomjones
2 Replies

7. Shell Programming and Scripting

perl (word by word check if a hash key)

Hi, Now i work in a code that 1-get data stored in the database in the form of hash table with a key field which is the " Name" 2-in the same time i open a txt file and loop through it word by word 3- which i have a problem in is that : I need to loop word by word and check if it is a... (0 Replies)
Discussion started by: eng_shimaa
0 Replies

8. Shell Programming and Scripting

Help adding a key word search to my script

Hello: I need help adding a key word search to my bash script. I have the following script. My boss whats the user to be able to add a search word e.g. unknown failures for the script to search the logs through and find the instances. I had originally done it so it grepped for unknown... (8 Replies)
Discussion started by: taekwondo
8 Replies

9. Shell Programming and Scripting

search for key word and execute

Hi, I am writing a shell (after 6-7 months)that has to receive text from another shell, check if the first line in the text has a key word and then execute different shell.I could come up with the below program structure, please suggest me if there is a better way to do it or please help me with... (14 Replies)
Discussion started by: rider29
14 Replies

10. UNIX for Dummies Questions & Answers

Searching for key word within a file

Hello, I have a directory that holds all of my matlab codes. I am trying to run a searh on all of the matlab files that have the word "while" written inside the sytax of the code. Looking for all of the times that I did a while loop. Can someone help me do this? Thanks in advance. ... (1 Reply)
Discussion started by: moradwan
1 Replies
Login or Register to Ask a Question