I'm trying to put together what I guess could be called a bash script (not that my bash-scripting abilities are anything to brag about). What I'm trying to do is feed a line from a text file--a text file whose content changes on a regular basis--to a program I'm invoking (imagemagick). It's so far working, but only if there is a single word or number sequence in the text file--I think because I'm trying to use a for
loop, and the loop somehow results in white space being treated as line breaks. So, when the file's content exceeds one word or numeral sequence, instead of the content from the file being fed to the program as a line of text, it looks like it gets fed one line at a time, and only the last line--pretty much a single word--gets incorporated in the end into the result. Not what I want.
I'll give an example using echo, since I think this will be simpler to demonstrate and understand that way. So I've got a text file, and let's say it's called myfile.txt
. It contains a single line with several words and numeric seqeunces. It might look as follows:
'Sep 09, 2016 - 01:00 PM EDT\nconditions: mostly cloudy\n34 F\nHumidity: 39%'
The single quotes are supposed to get the program I'm feeding this material to to treat it as a whole and ignore white space. The \n bits are required by the program I'm feeding it to, and they function in that program as line break indicators. So, using this example with a for
loop and the echo command, a line like the following
for i in `cat myfile.txt`; do echo $i; done
produces output not
'Sep 09, 2016 - 01:00 PM EDT\nconditions: mostly cloudy\n34 F\nHumidity: 39%'
but
'Sep
09,
2016
-
01:00
PM
EDT\nconditions:
mostly
cloudy\n34
F\nHumidity:
39%'
From what I'm reading, it seems like using a loop that invokes cat is not a very good way to accomplish what I'm after, and that the loop may well be the cause of the content ending up spread across several lines rather than all together. So, can anyone suggest a way of doing this that will cause all those words and integer groups to end up on the same line?
PS : The script I'm trying to create starts off with #!/bin/bash
and consists in a series of commands. It downloads a text file from which most of the content gets deleted and is renamed to myfile.txt
. After that it downloads a weather map and performs some operations on it (mainly cropping). The idea is to use imagemagick to juxtapose some text onto that map/image. In fact, it's already working, so long as I do not try to include multiple words or integer sequences divided by white space. If I exceed a single word or integer sequence in the text file, only the last word or integer sequence gets juxtaposed onto the image.
cat myfile.txt
. As an argument is would look as follows:command "$(cat myfile.txt)"
– chaos Aug 10 '16 at 05:47