Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read data from a file in UNIX Script

Status
Not open for further replies.

Trancemission

Technical User
Oct 16, 2001
108
GB
I have a file that contains 1 number, i need to create a shell script that when ran will take the data in the file (1 number) and execute another program with the number passed in the command line

Cheers
 
What about this?

myprogram `cat number_file`

Greg.
 
Here is a simple example:

Content of file:
100

#!/bin/sh

#Get the number in the file
FILE_NUMBER=`cat file`

#Pass it to another program, simple echo example
echo $FILE_NUMBER

exit 0


-Tony
 
I'm still getting problems, here is my script:

#!/usr/bin/sh
echo "Receieved Values $1"
echo "Executing Alarm Receptor"
/testing/alarmpt $1 'cat number'

This script reieves a variable, and then tries to execute /testing/alarmpt with the variable that was passed to it and also the number in the file 'number'

Hope you can help

Cheers

PS the echo's are just for debugging
 
What errors are you seeing?

The line below does not look right:

/testing/alarmpt $1 'cat number'

should be /testing/alarmpt $1 `cat number`

The quotes you used are wrong.


-Tony
 
It looks like you have cat number inside apostrophes - ' ... change them to backticks - ` (above the TAB key).

Backticks tell the shell to execute the commands contained therein.

You can also use $(cat number) as an alternative to `cat number`

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top