[SOLVED] foo1=$(cat foo2) does not work as expected (by me).
Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Why does not the whole output of 'cat radios' go into u12? I suspect it has something to do with the newline char, but do not exactly understand why it fails. Thanks.
Can you check the value of IFS. A newline would be translated to space when you do something like this but should still contain all the lines of the file.
also try with bash -x to see what is happening along with trying to see if the values were stored in array by printing the size of u12 as
Yes. Just after posting I suspected the file from where radio came from could have <CR><LF> line terminators. I used vim's 'set ff=unix' command to remove the carriage return chars, and hexdump showed the <CR>s where gone.
After that, I get the same output as you for the command 'echo $u12' and, yes, I would like the <CR> to remain. Thanks a lot.
*** I overlooked the rest of smoker's post. Sorry.
+1 to smoker's idea that the problem in in the file, not in the bash commands and that you need to double quote the variable when echoing it. I don't believe $IFS is relevant except when echoing $u12 without quotes. Here's experimenting with IFS:
c@CW8:/tmp$ u12=$(cat radios)
c@CW8:/tmp$ echo "$u12"
Antena 2: mms://220.127.116.11/antena2 (para mplayer).
Arnold Schoenberg: http://18.104.22.168:8000/listen.pls
c@CW8:/tmp$ echo $u12
Ant na 2: mms://22.214.171.124/ant na2 (para mplay r).
Arnold Scho nb rg: http://126.96.36.199:8000/list n.pls
c@CW8:/tmp$ unset IFS
c@CW8:/tmp$ echo $u12
Antena 2: mms://188.8.131.52/antena2 (para mplayer). Arnold Schoenberg: http://184.108.40.206:8000/listen.pl
Note: in bash, unsetting IFS is equivalent to it having its default value.