need to pass value while running the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to pass value while running the script
# 1  
Old 07-19-2012
need to pass value while running the script

hi
i am trying to write a script in which i want to pass a value and that value should be
compare with a value which was already define in a script .
if the value is correct the sj=how access esle show access denied.

below is my script: this is not working.
Code:
#!/bin/ksh
  echo "The value of the first argument to the script :" $1
  p=$1
  passwod="asr"
  read p
  if  “$p" == "$password" ]; then
          echo "You have access!"
  else
          echo "ACCESS DENIED!"
  fi

i also make few changes that also not help me.
below is the changes i made .
Code:
#!/bin/ksh
  read $1
  echo "The value of the first argument to the script :" $1
  passwod="asr"
  #read $1 
  if  [`$1` == "$password" ]; then
          echo "You have access!"
  else
          echo "ACCESS DENIED!"
  fi

but getting below o/p
Code:
$ e3 asr

The value of the first argument to the script : asr
                                   -> "at this blank space cursor blink then ii again enter the asr"
e3[8]: asr:  not found.
e3[8]: test: 0403-004 Specify a parameter with this command.
ACCESS DENIED!
$

please suggest
# 2  
Old 07-19-2012
Code:
#!/bin/ksh

echo "The value of the first argument to the script: $1"
password="asr"

if  [ $1 == "$password" ]
then
    echo "You have access!"
else
    echo "ACCESS DENIED!"
fi

Quote:
Originally Posted by scriptor
"at this blank space cursor blink then ii again enter the asr"
read is used to take input from user. That's why you saw what you quoted.
# 3  
Old 07-19-2012
Java

this mean that "read" will not read the parameter which i pass initially.
and i have to enter value for "read" again?
# 4  
Old 07-19-2012
passwod="asr" and if has password

Look at you script you have defined the variable passwod and you are testing the condition with $password
# 5  
Old 07-19-2012
Java

thx for pointing out. but still getting err.

Code:
$ cat e3
#!/bin/ksh
read $1
echo "The value of the first argument to the script :" $1

password="asr"

if  [$1 == "$password" ]; then
        echo "You have access!"
else
        echo "ACCESS DENIED!"
fi

below is the o/p
Code:
$ e3 asr
asd
The value of the first argument to the script : asr
e3[8]: [asr:  not found.
ACCESS DENIED!
$

in this script i want to pass $1 value to password but this is not happening
# 6  
Old 07-19-2012
@scriptor: Please read post #2 above.
# 7  
Old 07-19-2012
i am not getting my answer

this mean that "read" will not read the parameter which i pass initially.
and i have to enter value for "read" again?

in this script i want to pass $1 value to password but this is not happening


correction already made.which was pointed out by maverick_here
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 pass values to a script called from within another script in shell?

Ceiling Light - The Forgotten Element One of the highest details concerning using an LED ceiling panel essentially offer a fantastic dance floor which definitely makes the customers dance right away.They are a quite low cost method of something like a lighting solution, simple collection up,... (1 Reply)
Discussion started by: harveyclayton
1 Replies

2. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

3. Shell Programming and Scripting

Need to pass arguments while running a Shell Script

Shell Script Gurus, I am writing a shell script which needs User ID's to pass as an Arguments in command line while executing. Can this be doable? I've never done this, If you give a sample script that would be helpful, Thanks. (1 Reply)
Discussion started by: shekar777
1 Replies

4. Shell Programming and Scripting

Pass script with parameter in korn shell script

I have written a script which will take input parameter as another script. However, if the script passed as input parameter has parameters then this script doesn't work. I have a script b.ksh which has 1 and 2 as parameters I have a script c.ksh which has 3,4 and 5 as parameters vi a.ksh... (1 Reply)
Discussion started by: Vee
1 Replies

5. 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

6. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

7. Shell Programming and Scripting

Pass parameters to a function and running functions in parallel

Hi , I have a script which is using a text file as I/P. I want a code where it reads n lines from this file and pass the parameters to a function and now this script should run in such a way where a function can be called in parallel with different parameters. Please find below my script, it... (1 Reply)
Discussion started by: Ravindra Swan
1 Replies

8. 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

9. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

10. UNIX for Advanced & Expert Users

Pass parameter to the main script from wrapper script

Hi, I am writing a wrapper script(wrap_script.sh) to one of the main scripts (main_script.sh) The main script is executed as following: ./main_script.sh <LIST> <STARTDATE> <ENDDATE> looks for a parameter which is a LIST(consists of different list names that need to be processed), START/END... (0 Replies)
Discussion started by: stunnerz_84
0 Replies
Login or Register to Ask a Question