Simple quick one - how to set a variable from a text file...
All I need to do is set a variable in a script from the contents of a text file.
text.file contains variable text in this file and I want to set a variable I can use in the script with that string: so I can get something like: echo "${title}" from within my script and get: variable text in this file The actual use is to get the contents of the file to act as the title in an ImageMagick convert -draw call: Code:
addTitleText=$(convert -fill white -draw 'text 100,100 '${title} /tmp/img.$rand /tmp/titled 2>&1) |
title=`cat file`
Cheers, Tink |
or
Code:
title = `< file` |
or
Code:
title=$(<file) |
or, if format is like so:
variable="thing" you can dot it: . text_file |
not understanding you Billy :? (bit new to some of this :) )
Thanks all, that has me sorted :) |
...actually it has me with one more problem...
I only get the first word of the title: Code:
++ convert -fill white -draw 'text 100,100 Strangers' on Mars /tmp/img.a6cc613fd9f7297ba78b1c3c8d /tmp/titled Code:
title=`< /tmp/title.txt` Strangers on Mars and so of course the spaces in the string are being seen by convert as separate files... Thanks guys :) Will |
Code:
title=$(</tmp/title.txt) Code:
addTitleText=$(convert -fill white -draw "text 100,100 '$(</tmp/title.txt)'" /tmp/img.$rand /tmp/titled 2>&1) |
Quote:
that did it jlliagre :cool: I guess I have much to understand about how the scripts interpret ' and " and when they are interchangable for different effect: ie program -option 'this needs "this here to work"' and program -option "this can 'be done this way if necessary'" :) |
i'm kinda not understanding the posts here but if you want the whole line or even the whole text of the file, you can do
Code:
variable="$(<file)" |
Quote:
Code:
variable=$(<file) Code:
variable="$(<file)" |
Quote:
The shell is removing the surrounding single or double quotes, the difference being variables are not expanded when single quotes are used, try for example: Code:
a=test |
Thanks very much for the clarification it is invaluable
I did try that and got: Code:
stardotstar@geko ~ $ ./testquote.sh Will |
Quote:
as it was always helpful to me when i'm doing: Code:
variable="text so i'll take note of that. thank you. regards :) Edit: if you're trying to append text btw. you can do Code:
variable"$(<file) new text" Code:
variable=$(<file)" new text" Code:
variable=$(<file) new text |
In the line:
Code:
addTitleText=$(convert -fill white -draw "text 100,100 '$title'" /tmp/img.$rand /tmp/titled 2>&1)' -draw 'text 100,100 "' "$title" "'" For example: Code:
title="$(<text)" |
All times are GMT -5. The time now is 07:59 PM. |