nixCraft Linux Forum

nixCraft

Linux 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

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 02-21-2007, 10:15 PM
Junior Member
 
Join Date: Feb 2007
Posts: 2
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
Sponsored Links
  #2 (permalink)  
Old 02-21-2007, 11:02 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
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 | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 02-22-2007, 02:38 PM
Junior Member
 
Join Date: Feb 2007
Posts: 2
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 02-22-2007, 03:36 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
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 | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


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 On

Similar Threads

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


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


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

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