LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-06-2012, 12:45 AM   #1
patrick295767
Member
 
Registered: Feb 2006
Distribution: FreeBSD, Linux, Slackware, LFS, Gparted
Posts: 664

Rep: Reputation: 138Reputation: 138
VAR="$VAR$IFS$NEWINPUT" not working


Hello,

I would like to had a \n line feed into my variable with new input lines NEWINPUT is for instance /tmp/tmp.i987/file1 and so on.

How would it be possible with variables?

thank you
 
Old 01-06-2012, 12:53 AM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Are you saying you want multiple file names within one variable, seperate by LF+CR? You are better off creating an array to do this, especially if you want actual control of how they are being stored and manipulated.

Cheers,

Josh
 
Old 01-06-2012, 12:55 AM   #3
patrick295767
Member
 
Registered: Feb 2006
Distribution: FreeBSD, Linux, Slackware, LFS, Gparted
Posts: 664

Original Poster
Rep: Reputation: 138Reputation: 138
Quote:
Originally Posted by corp769 View Post
Are you saying you want multiple file names within one variable, seperate by LF+CR? You are better off creating an array to do this, especially if you want actual control of how they are being stored and manipulated.

Cheers,

Josh
something similar to

Code:
echo "/tmp/tmp.i987/file1" > /tmp/test.txt
echo "/tmp/tmp.i987/file2" >> /tmp/test.txt
echo "/tmp/tmp.i987/file3" >> /tmp/test.txt
... 

VAR=`cat /tmp/test.txt`
 
Old 01-06-2012, 01:01 AM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Yes, you could do it like that, but what do you need to actually do with the variable? I am asking because if you use an array, you can use a loop to cycle through and increment a variable, and you can manipulate each file name independently.
 
Old 01-06-2012, 01:49 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Or to be even more clear, this has all the hallmarks of a classic XyProblem.

What we really want to know is what your ultimate goal is, so that we can tell you how to do it right, and not just help you to do it the wrong way better.
 
1 members found this post helpful.
Old 01-06-2012, 02:10 AM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Quote:
Originally Posted by David the H. View Post
Or to be even more clear, this has all the hallmarks of a classic XyProblem.

What we really want to know is what your ultimate goal is, so that we can tell you how to do it right, and not just help you to do it the wrong way better.
True, you have a point. I'm just forking out ideas.... But on that note, to the OP - What exactly are you trying to do?

Last edited by corp769; 01-06-2012 at 06:03 AM.
 
Old 01-06-2012, 04:18 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
Code:
$ VAR="$VAR"$'\n'$(date)
$ VAR="$VAR"$'\n'$(date)
$ VAR="$VAR"$'\n'$(date)

$ echo "$VAR"

Fri Jan  6 11:17:25 CET 2012
Fri Jan  6 11:17:26 CET 2012
Fri Jan  6 11:17:26 CET 2012

Last edited by NevemTeve; 01-06-2012 at 04:20 AM. Reason: -e is unnecassary in echo
 
Old 01-06-2012, 05:53 AM   #8
patrick295767
Member
 
Registered: Feb 2006
Distribution: FreeBSD, Linux, Slackware, LFS, Gparted
Posts: 664

Original Poster
Rep: Reputation: 138Reputation: 138
Quote:
But on that note, to the OP - What exactly are you trying to do?
I do not understand to question. Simply to do as below:

Quote:
Originally Posted by NevemTeve View Post
Code:
$ VAR="$VAR"$'\n'$(date)
$ VAR="$VAR"$'\n'$(date)
$ VAR="$VAR"$'\n'$(date)

$ echo "$VAR"

Fri Jan  6 11:17:25 CET 2012
Fri Jan  6 11:17:26 CET 2012
Fri Jan  6 11:17:26 CET 2012
thank you!

Last edited by patrick295767; 01-06-2012 at 05:55 AM.
 
Old 01-06-2012, 06:03 AM   #9
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Oh ok, fair enough then!
 
  


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] printf $"Hello $var\n" vs. printf "Hello $var\n" -- not a typo. What is it? GrapefruiTgirl Programming 2 10-21-2010 08:21 AM
if [ "$VAR"="string" ] always testing TRUE JohnE1 Programming 2 08-05-2008 08:35 PM
c gurus: whats the diff? "var[]" and "*var"? kourama Programming 16 04-03-2007 10:28 AM
Renamed bogus "/var/mail/macleanl" into "/var/mail/BOGUS.macleanl.xPVB" paul_mat Linux - Networking 1 07-04-2006 12:50 PM
sshd error " bad owner or mode for /var/empty" piraxter Slackware 1 09-09-2003 11:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:24 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