nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Passing value from variable while its expected from keyboard

This is a discussion on Passing value from variable while its expected from keyboard within the Shell scripting forums, part of the Development/Scripting category; I have written a small script to execute a program which is written in c++. Now the program expects input ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 21-02-2007, 09:15 PM
Junior Member
User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
unix11
Default Passing value from variable while its expected from keyboard

I have written a small script to execute a program which is written in c++. Now the program expects input from keyboard while i need to pass that from the variable. How can I do that? Pardon me..i am a beginner.
Reply With Quote
  #2 (permalink)  
Old 21-02-2007, 10:02 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

It is possible to pass variable using standard I/O or just variable. For example:
Code:
A=”/tmp/file.txt”
gedit $A
Another option is use < input redirect option
Code:
#!/bin/sh
echo $var > /tmp/input
/path/to/c.prog < /tmp/input
gedit will open /tmp/file.txt file. You may have to modify c++ program try above and let me know. You can pass / play with argc and argv in main(). If argc is zero ask for input else read from command line via shell variable.

Let me know if you need any help
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 22-02-2007, 01:38 PM
Junior Member
User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
unix11
Default

Thanks nix

i am calling a program called "cdrtool" . I cant modify this program.

when I normally execute from command line
$ cdrtool m12 p

The 'p' is to get the input from keyboard. But i wanted to pass this value from a file. It takes the input and gives me an input.
so tried like this (which was not working)

#!/bin/sh

ls -1 *.asc > file1
cat file1 | \
while read line
do
cdrtool m12 p | $line
done
rm file1
exit

now i have changed this to as below and it works

#!/bin/sh

ls -1 *.asc > file1
cat file1 | \
while read line
do
echo $line | cdrtool m12 p
done
rm file1
exit

Anyway thanks a lot for ur reply..i will aslo try ur method and learn how it works. Since i will be learning more in coming days, I may have questions for which i would need ur help. Thanks.
Reply With Quote
  #4 (permalink)  
Old 22-02-2007, 02:36 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 244 Times in 183 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

There are many ways to solve one problem. I’m glad that you sorted it out with pipes
Quote:
Since i will be learning more in coming days, I may have questions for which i would need ur help. Thanks.
Sure forum is for discussion. Feel free to use whenever you need help!
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
SSH - Passing Unix login passwords through shell scripts arulkumarr Shell scripting 4 27-08-2008 09:22 PM
passing options to a shell script bigpaw Shell scripting 2 11-10-2007 02:40 AM
How do I turn off the power button on sun keyboard? monk Solaris/OpenSolaris 0 30-01-2007 02:12 AM
Linux usb keyboard does not work jerry Linux software 3 05-04-2006 09:21 PM
HTML variable nathan86 Linux software 3 23-03-2005 12:29 PM


All times are GMT +5.5. The time now is 09:09 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38