Bash Script: For-Loop Over Newline… Syntax Explained?

A frequently asked question both on SO and elsewhere is how to use a bash for-loop to go over each line of output. I'm aware of the answer, and I've been happily using the following for years now:

IFS=$'\n'

However, I'm slightly perplexed by the syntax used. I've had a good search / Google, but due to the sheer number of symbols which are used / ignored by search engines in the above - I've not found an explanation.

I've also recently spotted this in some output from another script. I was having problems echoing the result from netcat. Upon closer inspection, it turns out that the output from nc was in a similar format:

$'Some_Output_Here\r`

I ended up needing to cut off the \r, but wasn't sure of the best way to go about it, I ended up using egrep -o ([0-9|a-Z]*). Any better ideas?

Answers


The Bash manual explains this quoting method, which it calls ANSI-C Quoting.


Need Your Help

VS2010 Add-in cpp/h automatic tab groups

c++ visual-studio-2010 add-in

Is there any Visual Studio 2010 add-in that will automatically group cpp and header files in different tab-groups, and also maybe automatically open/close corresponding cpp/header files when openin...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.