- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- read file data into a variable
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
Forums
Discussions
Discussions
Discussions
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
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
03-06-2003 11:27 AM
03-06-2003 11:27 AM
I have a script that needs to read the date from a file and put it into a variable. The file only has one row and one column of data. For example,
> more date_file.dat
20030331
I'm trying to read date_file.dat and put it into var1. I only need to do this once so I don't need a loop or anything.
Thanks for the help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 11:33 AM
03-06-2003 11:33 AM
Re: read file data into a variable
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 11:35 AM
03-06-2003 11:35 AM
Re: read file data into a variable
If date_file.dat just have the date info:
VAR1=`cat date_file.dat`
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 11:35 AM
03-06-2003 11:35 AM
Re: read file data into a variable
You can also do it this way:
VAR1=$(
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 11:36 AM
03-06-2003 11:36 AM
Re: read file data into a variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 11:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 11:37 AM
03-06-2003 11:37 AM
Re: read file data into a variable
for var1 in `date_file.dat`
do
whatever comman you want to do with var1
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 11:39 AM
03-06-2003 11:39 AM
Re: read file data into a variable
Do this:
VAR=`< data_file.dat`
...or:
VAR=$(< data_file.dat)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2003 01:23 PM
03-06-2003 01:23 PM
Re: read file data into a variable
I think you will find the input redirection is faster than spawning 'cat' to read the file and capture the first line into your variable.
In fact, this is documented in the 'sh-posix' man pages:
/begin_quote/
The command substitution $(cat file) can be replaced by the equivalent but faster $(
/end_quote/
...while I am an animal lover, including mmembers of the feline species, I avoid cat's whenever possible! :-;
Regards!
...JRF...