- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- providing a shell script with parameters from a fi...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2003 07:07 PM
тАО10-16-2003 07:07 PM
got a question. i've written a script which contains several variables. because i'd like to run a script each time with different variables values, the most convenient solution seems to be storing the values in a text file. is it possible that a script takes values for it's variables from a file (e.g. using '<' operator)?
thank you in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2003 07:20 PM
тАО10-16-2003 07:20 PM
Re: providing a shell script with parameters from a file
ie
./script -op
sources file operator.env
and
./script -ad
sources file admin.env
where admin.env contains
export VARIABLE1=one
export VARIABLE2=two
etc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2003 07:21 PM
тАО10-16-2003 07:21 PM
Re: providing a shell script with parameters from a file
VAR1=
STRING1=
Then you source this file with .
eg. put these 2 lines above into a file called VARIABLES then from your shell or from a script do;
. ./VARIABLES
This then sources the file and sets up these variables exactly as the are in the file, you can then run your script using these variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2003 07:22 PM
тАО10-16-2003 07:22 PM
Re: providing a shell script with parameters from a file
Within your script, positional parameters are referenced as $1, $2 etc, with $0 the whole line.
You can run your script based on the contents of textfile, a line at a time, using the following shell command:
--
while read line
do
yourscript.sh "$line"
done < textfile
--
Note the double quotes are needed around "$line" to get the whole line into the script, without them you'd only get the first parameter, not the entire line.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2003 08:11 PM
тАО10-16-2003 08:11 PM
Re: providing a shell script with parameters from a file
could you please tell me what structure a text file should have?
e.g each variable in separate line?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2003 09:38 PM
тАО10-16-2003 09:38 PM
SolutionIf you have a parameter file, make sure it contains all variables for one instance on one line. Then you can do it using the command read.
It will look something like this:
while read parm1 parm2 parm3 ...
do
do_actions
done < param_file
Good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2003 09:41 PM
тАО10-16-2003 09:41 PM
Re: providing a shell script with parameters from a file
There are loads of examples on the system.
For example, have a look at
"/usr/sam/lbin/ioparser.sh" around line 474, where 19 variables are read from a single line.
--
-- Graham