Computing.Net > Forums > Unix > Pass options from script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Pass options from script

Reply to Message Icon

Name: bosman
Date: March 21, 2005 at 05:25:21 Pacific
OS: Solaries
CPU/Ram: 4GB
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 21, 2005 at 06:40:53 Pacific
Reply:

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



0

Response Number 2
Name: vibhor_agarwalin
Date: March 21, 2005 at 20:15:15 Pacific
Reply:

Hello,

Whats a Unix here document.
Can you help me a bit with that.

Vibhor Kumar Agarwal


0

Response Number 3
Name: nails
Date: March 21, 2005 at 22:16:25 Pacific
Reply:

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
HERE

You can ever embed shell variables in here documents:

x=whatever
cat << HERE
Enter a shell variable
$(echo $x)
HERE


0

Response Number 4
Name: bosman
Date: March 22, 2005 at 04:00:41 Pacific
Reply:

Thank you, using here documents solved my problem.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Pass options from script

Pass parameters from a file www.computing.net/answers/unix/pass-parameters-from-a-file/5164.html

passing file to script www.computing.net/answers/unix/passing-file-to-script/7544.html

Pass parameter from plsql to unix www.computing.net/answers/unix/pass-parameter-from-plsql-to-unix/6500.html