- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- scripting on bash - reading values to multiple var...
Operating System - Linux
1748112
Members
3302
Online
108758
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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-16-2008 05:51 AM
тАО03-16-2008 05:51 AM
hello,
on ksh - the following syntax would work -
echo 1 2 3 | read a b c
a would contain '1', b would contain '2' and c would be 2.
on bash it wouldn't work... no data will be read into these variables.
does anyone know how can I do that on bash? looking for elegant solution. I don't want set each variable seperatly.
thanks
ITai
on ksh - the following syntax would work -
echo 1 2 3 | read a b c
a would contain '1', b would contain '2' and c would be 2.
on bash it wouldn't work... no data will be read into these variables.
does anyone know how can I do that on bash? looking for elegant solution. I don't want set each variable seperatly.
thanks
ITai
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2008 06:33 AM
тАО03-16-2008 06:33 AM
Solution
Hi ITai,
from ksh(1) "ksh -- Public domain korn shell"
section "BUGS"
<...>
BTW, the most frequently reported bug is
echo hi | read a; echo $a # Does not print hi
I'm aware of this and there is no need to report it.
Bash:
$ A=( $( echo X Y Z) )
$ echo ${A[2]}
Z
$echo ${A[*]}
X Y Z
rgds
HGH
from ksh(1) "ksh -- Public domain korn shell"
section "BUGS"
<...>
BTW, the most frequently reported bug is
echo hi | read a; echo $a # Does not print hi
I'm aware of this and there is no need to report it.
Bash:
$ A=( $( echo X Y Z) )
$ echo ${A[2]}
Z
$echo ${A[*]}
X Y Z
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2008 06:57 PM
тАО03-16-2008 06:57 PM
Re: scripting on bash - reading values to multiple variables
This topic also appears as question E4 of the bash FAQ at http://tiswww.case.edu/php/chet/bash/FAQ .
The trick is that the variables are set but the values don't come back from the child shell that reads the pipe to the parent shell that you want the variables set in. You can instead use `echo 1 2 3` or $(echo 1 2 3) to expand the output of a command into arguments for another statement.
One way to rewrite it in bash or recent ksh is with a 'here string'-
read a b c <<< $(echo 1 2 3)
The trick is that the variables are set but the values don't come back from the child shell that reads the pipe to the parent shell that you want the variables set in. You can instead use `echo 1 2 3` or $(echo 1 2 3) to expand the output of a command into arguments for another statement.
One way to rewrite it in bash or recent ksh is with a 'here string'-
read a b c <<< $(echo 1 2 3)
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP