LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-18-2021, 03:20 PM   #1
dmiraj
LQ Newbie
 
Registered: Feb 2021
Posts: 2

Rep: Reputation: Disabled
Why does $IFS contain '$' only


Hello all,
When issuing the following command
Code:
cat -A <(echo $IFS)
. The output is $ . But this is not what $IFS is supposed to be,as indicated in the man page:
Code:
<space><tab><newline>
.

So why is it equal to $, but word splitting happens just fine.

I am using Ubuntu.

Thank you.
 
Old 12-18-2021, 03:38 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,143

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
The bash man page says <space><tab><newline> is the default value, which is the value when IFS is not set.
 
Old 12-18-2021, 04:00 PM   #3
enigma9o7
Senior Member
 
Registered: Jul 2018
Location: Silicon Valley
Distribution: Bodhi Linux
Posts: 1,388

Rep: Reputation: 560Reputation: 560Reputation: 560Reputation: 560Reputation: 560Reputation: 560
It doesn't. You put -A switch onto cat which makes it display $ on every line.

Code:
cat --help
says
Code:
  -A, --show-all           equivalent to -vET
  -b, --number-nonblank    number nonempty output lines, overrides -n
  -e                       equivalent to -vE
  -E, --show-ends          display $ at end of each line
  -n, --number             number all output lines
  -s, --squeeze-blank      suppress repeated empty output lines
  -t                       equivalent to -vT
  -T, --show-tabs          display TAB characters as ^I
  -u                       (ignored)
  -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB
Since -A does -vET and -E prints a $ on every line, you get your $

Last edited by enigma9o7; 12-18-2021 at 04:03 PM.
 
Old 12-18-2021, 04:43 PM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,609

Rep: Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552Reputation: 2552

It's showing "$" because you haven't quoted the variable and so the evaluated command being run is "cat -A <(echo)" and the echo is outputting a newline character.

If you quote the variable you will get the contents of it included in the command, and if you use -n option you can prevent echo outputting the trailing newline character, i.e:
Code:
$ cat -A <(echo -n "$IFS")
 ^I$

Last edited by boughtonp; 12-18-2021 at 04:46 PM.
 
1 members found this post helpful.
Old 12-26-2021, 07:56 AM   #5
dmiraj
LQ Newbie
 
Registered: Feb 2021
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by boughtonp View Post
It's showing "$" because you haven't quoted the variable and so the evaluated command being run is "cat -A <(echo)" and the echo is outputting a newline character.

If you quote the variable you will get the contents of it included in the command, and if you use -n option you can prevent echo outputting the trailing newline character, i.e:
Code:
$ cat -A <(echo -n "$IFS")
 ^I$
Thank you, this makes sense to me now.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Been bitten by IFS yet again: 'mkinitrd_command_generator.sh --run' fails if IFS not set to space. luvr Slackware 3 06-20-2019 04:09 PM
Does IFS only work on variable expansion? glenjoker Linux - Newbie 7 10-15-2015 09:30 AM
Bash: when an empty IFS does not work like a default IFS (info) catkin Programming 13 04-19-2012 09:40 AM
[SOLVED] How to find files that contain one string, but don't contain another. PatrickDickey Linux - Newbie 2 09-11-2011 06:00 AM
list graphics only for a IFS loop wonderfullyrich Programming 5 12-30-2009 09:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration