Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am writing a shell script that automates the installation of a certain software tool. The problem is that the installer requires the users to enter some options during installation, so this requires me to watch the script while running. My question is can I send these options from the script directly without the need to manually enter them.

If you know the input to the installer, you can:
1) place the input in a file and redirect it to the installer:
installer < input
2) call the installer using a unix here document:
installer << MSG
your input
goes here
MSG

A unix document allows you to redirect standard input from the key board to lines in your shell script. You have to use the I/O redirection operator followed by an arbirary delimiter word.
The input lines start after the CR that follows the delimiter and continue up to the 2nd delimiter word. This delimiter is on a line all by itself.
Let's look at an example. Consider when you prompt the user for input:
echo "enter x"
read x
echo "x is: $x"Here's an example of a unix here document:
echo "enter y"
read y << MSG
whatever
MSG
echo "y is: $y"
# make sure there's no white space after
# the delimiter MSG.In the above example, variable y is automatically assigned the value: whatever - from the script.
Another typical use of a here document is replacing a block of echos:
echo "this is line 1"
echo "this is line 2"
echo "this is line 3"# here document:
cat << HERE
this is line 1
this is line 2
this is line 3
HEREYou can ever embed shell variables in here documents:
x=whatever
cat << HERE
Enter a shell variable
$(echo $x)
HERE

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |