- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Does double quoting a variable in echo imply a...
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
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
тАО01-18-2005 03:25 AM
тАО01-18-2005 03:25 AM
# print $arecs | vis -n
one\sthree\sfive\n
Consider these outputs.
# echo $arecs
one three five
# echo ${arecs}
one three five
but why....
# echo "$arecs"
one
three
five
Does double quoting possess an un- or unclearly-documented implicit IFS? Note that IFS was (intentionally) not set when the output above was obtained.
Thanks!
Solved! Go to Solution.
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2005 03:39 AM
тАО01-18-2005 03:39 AM
Re: Does double quoting a variable in echo imply a default IFS?
I just did a test and I did NOT see the same behavior.
# export TEST="one 2 three 4 five"
# echo $TEST
one 2 three 4 five
# echo ${TEST}
one 2 three 4 five
# echo "${TEST}"
one 2 three 4 five
# echo "$TEST"
one 2 three 4 five
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2005 03:43 AM
тАО01-18-2005 03:43 AM
Re: Does double quoting a variable in echo imply a default IFS?
posix under 11.11.
more info which I inadvertently left out..
I created the variable from output of a grep.
Heres the source file:
# cat /tmp/tmp.tmp
one A
two B
three A
four B
five A
Heres the assignment:
arecs=$(grep "A" /tmp/tmp.tmp | cut -f 1)
Not sure if this clarifies or further confuses...
- Tags:
- command substitution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2005 03:50 AM
тАО01-18-2005 03:50 AM
Re: Does double quoting a variable in echo imply a default IFS?
echo $arecs
will be parsed by the shell and the new lines will be seen as parameter seperaters, which will be stripped and the arguments will be displayed with the standard OFS (space).
echo "$arecs"
will be parsed by the shell and the contents of arecs will not be parsed and output as is. So embedded new line characters will be displayed along with the text.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2005 04:21 AM
тАО01-18-2005 04:21 AM
Re: Does double quoting a variable in echo imply a default IFS?
$arecs had:
one-space-two-space-three-newline
# print $arecs | vis -n
one\sthree\sfive\n
To extend your explanation a bit, with the variable in double quotes (echo "$arecs"),
if the shell finds *any* newline, all field separators then become newline? e.g., the presence of one newline at the end supercedes the spaces?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2005 05:37 AM
тАО01-18-2005 05:37 AM
Re: Does double quoting a variable in echo imply a default IFS?
print "$arecs" | vis -n
and I think you'll see the \n in between each text.
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2005 07:25 AM
тАО01-18-2005 07:25 AM
SolutionBill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2005 12:15 AM
тАО01-19-2005 12:15 AM
Re: Does double quoting a variable in echo imply a default IFS?
As Bill said, when you use
... # cmd "$var"
you are telling the shell parser that this is one argument to 'cmd' -- shell does no processing on $var's contents and just passes it as is, newlines and all. Thus, 'echo' sees *one* argument, including the newlines which he dutifully echoes back out.
When you use
... # cmd $var
the shell *is* parsing $var's contents and all whitespace, including newline, is treated as an argument delimiter and is dropped from the arguments passed to 'cmd'. In this case, 'echo' simply sees *3* arguments, with no newlines.
It's similar to:
... # for x in 1 2 3 ; do echo ... $x; done
... 1
... 2
... 3
versus:
... # for x in "1 2 3" ; do echo ... $x; done
... 1 2 3
hth
bv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-19-2005 12:54 AM
тАО01-19-2005 12:54 AM
Re: Does double quoting a variable in echo imply a default IFS?
I figured the shell was doing what it was designed to, but could get a clear description of the design...