how to give a variable to a command in shell script...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to give a variable to a command in shell script...
# 1  
Old 08-17-2006
how to give a variable to a command in shell script...

hi all...
I am executing a comman in a shell script but the command needs a user input of character 'y' as input so it stops in between...may i know is there is any way of giving that character as input in the shell script itself???...thanks in advance....
# 2  
Old 08-17-2006
Using expect is one way to deal with the interactive apps.

But i think you can also try here document style like

command <<EOF
yes
true
and_so_on
EOF

This will invoke the command and supplies the responses between <<EOF and EOF
# 3  
Old 08-17-2006
i tried the <<EOF true EOF thing now it's not working mate.....actaully my input to the command is "y"...so i gave like my command<<EOF y EOF....this is what u said rite????
# 4  
Old 08-17-2006
If u like to give y as user input

read x
if [ x == "y"] ; then

#write your code

else

echo "Input is wrong"

fi

you like to add the value y in the script itself

x="y"

if [ x == "y" ] ; then

#write your code

fi
# 5  
Old 08-17-2006
Quote:
Originally Posted by santy
i tried the <<EOF true EOF thing now it's not working mate.....actaully my input to the command is "y"...so i gave like my command<<EOF y EOF....this is what u said rite????
no, that not what's been said.
Code:
command <<EOF
y
EOF

# 6  
Old 08-17-2006
yeah i tried the same but it's not working:-(
# 7  
Old 08-17-2006
What is your shell ? sh, bash, ksh, csh ....
Try this example:

script file yn.sh
Code:
echo "Confirm system destruction ?"
read confirm

if [ "$confirm" = y ]
then
   echo "System destruction confirmed."
   echo "Booom !!! "
else
   echo "Tomorrow perhaps."
fi

Excute script:
[CODE]
Code:
$ sh yn.sh <<EOF
y
EOF
Confirm system destruction ?
System destruction confirmed.
Booom !!!


Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script variable $1 used with put command

I have the following script used, i am new to shell scripting. tryign to understand. in the put $BASE_FOLDER/$base_name holds which path. What does it mean by $1 second path in put command is it constructing this path: /user/hive/warehouse/stage.db/$1 what is $1 holding in above path. ... (2 Replies)
Discussion started by: cplusplus1
2 Replies

2. Shell Programming and Scripting

sed command not accepting variable in shell script

I am using a shell script in fedora linux. While calling to the shell I am also passing an argument (var1=0.77) like shown below sh gossip.sh var1=0.77 in the shell following command is written (which doesn't work) sed - i -e 's@prob=@prob="$var1";//@g' file.txt Actually i want the... (7 Replies)
Discussion started by: Fakhar Hassan
7 Replies

3. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. 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... (2 Replies)
Discussion started by: Ashunayak
2 Replies

4. UNIX for Dummies Questions & Answers

How to give multiple inputs to a shell script

Got struck while trying to write a shell script which should automatically give input. While running a script for eg: (adpatch.sh) It Prompts for Multiple inputs like: Do you currently have files used for installing or upgrading the database installed in this APPL_TOP ? need to give... (2 Replies)
Discussion started by: abdmoha
2 Replies

5. Shell Programming and Scripting

store last command exit status in variable in shell script

Hello All My req is to store the exit status of a command in shell variable I want to check whether the file has header or not The header will contain the string DATA_ACQ_CYC_CNTL_ID So I am running the command head -1 $i | grep DATA_ACQ_CYC_CNTL_ID Now I have to check if... (6 Replies)
Discussion started by: Pratik4891
6 Replies

6. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

7. Shell Programming and Scripting

How to assign the result of a SQL command to more than one variable in shell script.

Hi Friends... Please assist me to assign the result of a SQL query that results two column, to two variables. Pls find the below code that I write for assigning one column to one variable. and please correct if anything wrong.. #! /bin/sh no=' sqlplus -s uname/password@DBname... (4 Replies)
Discussion started by: little_wonder
4 Replies

8. Shell Programming and Scripting

Perl script variable to read shell command

Solaris 10 Korn shell ksh, Hi there, I have figured out to get yesterday's date which is using the below command: TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and TZ=GMT+24; date +%Y%m%d to get the format of 20080930. I need this two format. In my perl script below I need... (4 Replies)
Discussion started by: bulkbiz
4 Replies

9. Solaris

i cannot give array declaration in shell script

Dear all, i m unable to give array decalartion in solaris Operating system shell script and script was so.sh declare -a bull for i in 1 2 3 4 5 6 7 8 9 do bull=$i echo "${bull}" done it is throwing an error called so.sh: declare: not found so.sh: bull=1: not... (20 Replies)
Discussion started by: naree
20 Replies

10. Shell Programming and Scripting

Can give the input to prompt using shell script

Hi, I want to send input to promt from shell script, this thing is possible. I give the one command `/usr/share/ssl/misc/CA -newreq` it needs some user input like password etc., but i need this input also from shell script but it does not works. `/usr/share/ssl/misc/CA -newreq` <<EOF... (2 Replies)
Discussion started by: Vaibhav Agarwal
2 Replies
Login or Register to Ask a Question