LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-05-2012, 07:42 AM   #1
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Rep: Reputation: Disabled
read command alternative


I have a script which is prompting for user input using "read" command & this script is read only.

I need to automate my process which is invoking the above script, i want to know is there any way by which i can supply the user input through some variables so that it wont halt my script & wait for user input// as normally above mentioned script will wait for user input

Please help
 
Old 11-05-2012, 07:45 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,386

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
most well written scripts will have ways to provide it formally, but you can generally use "expect" to wrap anything where this is not possible.
 
Old 11-05-2012, 08:13 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Is user's input same all the time? If yes, then you can store that value in a variable, and can declare that variable in the script itself. So u won't need use read statement. Else for varying input you'll need to wait for user's input.

Last edited by shivaa; 11-05-2012 at 08:15 AM.
 
Old 11-05-2012, 08:17 AM   #4
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 761
Blog Entries: 2

Rep: Reputation: 197Reputation: 197
That script might be read-only but when you take a copy of it you'll be able to change that.
 
Old 11-05-2012, 08:28 AM   #5
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
Thanks Chris for responding ,, but i dont have "expect" installed on my machine & worse thing is i dont have the access to do that

is there any other way by which i can automate the interactive script ???

pls suggest
 
Old 11-05-2012, 08:37 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,386

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
without seeing the script, we can only give generic solutions really.
 
Old 11-05-2012, 08:53 AM   #7
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
Below is the snapshot of my script,

*******************************

echo "Enter the directory location ="
read location

echo "Location enterd is $location"


*************************************

I want to automate in a way such that i can provide the location variable in an automated fashion

please suggest
 
Old 11-05-2012, 09:42 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,140
Blog Entries: 54

Rep: Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791
*You may think
Code:
echo "Location enterd is $location"
is true but cnsider it is not until after you checked its existence and the user being allowed to read / write to it. SoMaybe see some Bash scripting guides wrt do's and don'ts:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://www.gnu.org/software/bash/man...ode/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/
http://wooledge.org/mywiki/BashFAQ?a...direct=BashFaq
http://wooledge.org/mywiki/BashPitfalls


Code:
#!/bin/bash
# Set default behaviour:
LANG=C; LC_ALL=C; export LANG LC_ALL
# Set debug mode until checked:
set -vx

[ -z "${_MY_LOCATION}" ] && while getopts l: OPT; do case "${OPT}" in l) \
 [ -d $(readlink -f "${OPTARG}") ] && _MY_LOCATION=$(readlink -f "${OPTARG}") \
 || exit 1;; *) exit 1;; esac; done; echo "Location is "${_MY_LOCATION}""
So then you've got two ways for supplying it:
Code:
# export or
env _MY_LOCATION=/some/path /path/to/script
# and
/path/to/script -l /some/path
 
Old 11-05-2012, 11:01 AM   #9
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
Thanks so much , i got the solution to my problem
 
Old 11-05-2012, 11:50 AM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,140
Blog Entries: 54

Rep: Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791Reputation: 2791
Quote:
Originally Posted by vicky007aggrwal View Post
Thanks so much , i got the solution to my problem
Then please post what you used and mark the thread solved.
 
Old 11-05-2012, 11:55 AM   #11
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 92

Original Poster
Rep: Reputation: Disabled
i used the below command


exec <log.txt

above command overiding the read command parameter
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
alternative command of stime() rambolinuxbuddy Linux - Software 1 09-07-2012 04:34 AM
lsof command alternative zeusys Linux - Newbie 2 09-04-2011 05:59 PM
Alternative to the script command ... ??? newbie01.linux Linux - Security 2 10-12-2009 10:20 AM
Alternative to host command for users ? frenchn00b Linux - General 2 05-06-2008 05:53 PM
QUOTA Command alternative? Echo Kilo Linux - General 1 11-15-2004 01:26 AM


All times are GMT -5. The time now is 07:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration