-   Linux - Newbie (
-   -   read command alternative (

vicky007aggrwal 11-05-2012 07:42 AM

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

acid_kewpie 11-05-2012 07:45 AM

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.

shivaa 11-05-2012 08:13 AM

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.

linosaurusroot 11-05-2012 08:17 AM

That script might be read-only but when you take a copy of it you'll be able to change that.

vicky007aggrwal 11-05-2012 08:28 AM

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

acid_kewpie 11-05-2012 08:37 AM

without seeing the script, we can only give generic solutions really.

vicky007aggrwal 11-05-2012 08:53 AM

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

unSpawn 11-05-2012 09:42 AM

*You may think

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:


# Set default behaviour:
# 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:

# export or
env _MY_LOCATION=/some/path /path/to/script
# and
/path/to/script -l /some/path

vicky007aggrwal 11-05-2012 11:01 AM

Thanks so much , i got the solution to my problem

unSpawn 11-05-2012 11:50 AM


Originally Posted by vicky007aggrwal (Post 4822711)
Thanks so much , i got the solution to my problem

Then please post what you used and mark the thread solved.

vicky007aggrwal 11-05-2012 11:55 AM

i used the below command

exec <log.txt

above command overiding the read command parameter

All times are GMT -5. The time now is 11:08 AM.