How to pass infomation to POV-Ray from a shell script - shell

How do I pass a variable from a shell script to POV-Ray? My desire would the ability to pass a variable as a command-line argument and then use that value in the .ini file or .pov file
Something like
POV-Ray +pass var=$imageNumber file.pov
And then being able to use var in POV-Ray
I realize that I could edit the .ini and .pov files in the script or use modulus to use the single frame variable as two variables, but both those solutions seem awkward.
I want to generate 1000s of extremely similar scenes. Each scene is exactly the same except that a heightmap uses a different image file as its source. Normally, I would use the animation tools in POV-Ray to generate multiple frames. However, I am already using the animation tools to cycle over a different property in each scene.

For *nix systems, use POV-Ray's file handling system to open the standard-in file in your .pov file
#fopen STDIN "/dev/stdin" read
#read (STDIN, var1, var2)
This will read from the standard-in for a comma separated list of POV literals. However, POV-Ray doesn't handle reading from a pipe; Thus, use herestrings (or heredocuments if you must use only sh compatible syntax) to fill stdin for POV-Ray.
For example, if run in the shell (works for bash):
povray "example.pov" <<<'"hello","world"'
Will fill the variables var1 and var2 from above with the values "hello" and "world" respectively. Note that quotes must be included around each string value in the list. This is because POV wants POV literals in the 'file' we are passing.
If you want to use an .ini file instead, just call the .ini file in place of the .pov file and everything will work as expected.
If you want more or less variable to be passed to the POV file, add or remove variable names from the #read directive and extend or trim the number you are passing to the same length.'
You can also pass shell variables like this. If foo contains "hello" including the quotes, and "example.pov" is expecting one string in the herestring, then
povray "example.pov" <<<$foo
will pass hello to the variable in the #read directive.
Additionally, you can other POV literals than stings, in that case use the relevant POV syntax the that literal type. However, you can't put POV expressions into the herestring. See the wiki page for more information.

As of POV-Ray 3.7 you can now declare constants in the INI file, and therefore the command line, with Declare=MyValue=24. This would be the same as a #declare MyValue=24; in a scene file. The value on the right-hand side must be a constant float value.
see the relevant manual entry
As long as you don't pass fractional values (or use extremely large sequence numbers), you should be able to use this as a component in the file name.

Related

How does the # work in Bash?

When I open BashBurn source I se:
mainmenu[7]="$bb_menu_8#check_path"
I don't know what does #check_path mean? And how does it work?
It doesn't mean any special in Bash alone: # is just a part of a string here. It could have a special meaning inside the BashBurn implementation, however.
It looks like it is a part of the translation framework used inside BashBurn. You can search it on your own on GitHub for example.
mainmenu is set in BashBurn.sh, which is then passed as the second argument to the bbmenu function. The function is defined in bbmenu.sh. There is a description of the syntax, including this information:
ALL ITEMS ARE SEPERATED BY AMPERSAND.
All you need to do now is to read the rest of the documentation in the bbmenu.sh file.

What do the at-signs in Rundeck's #option.message# example mean to bash?

The Rundeck docs give the example of defining a message option (parameter) which can then be referred to by the script in a number of ways, including
echo message=#option.message# ;# replacement token
We use this syntax and it seems fine, but I have no idea what those two #s actually mean to bash; I can't find mention of anything beyond $#, or anything relevant for the "replacement token" in the comment.
Per the docs you linked, that is a "replacement token" handled by Rundeck. That is, Rundeck replaces the #...# before passing the command to bash. Consequently, they don't mean anything to bash :) . Specifically, the docs say:
Inline Script workflow steps that contain a token expansion will be expanded into a temporary file, and the temp file will contain the plaintext option value.
So bash sees the temp file post-expansion, without the #...# sequences and with their values as literal text.
The docs also note that "If the option is blank or unset the token will be replaced with a blank string." Therefore, the whole #...# sequence will disappear if a particular token is not defined.
See also this section on script usage and this section on context variables in the docs.

dynamically allocate variables in bash

I've encountered a problem in my bash script.
I need to assign new variables according to files in my folder and assign them a number according to the amount of arguments the script gets (whether it's a script or not).
I'm trying to get a script written like this:
n_${array[*]}=`arg_count ${array[*]}`
while arg_count checks how many parameters a script gets.
for further use, I'm going to change those variables if there's a function with different arguments needed.
Thanks in advance!
In general, you can use the declare builtin to accomplish this, because it is a command whose argument is a string that resembles an assignment.
declare "n_${array[*]}=$(arg_count ${array[*]})"
However, note that unless you set IFS appropriately and the array contents are amenable, the expansion of ${array[*]} isn't going to be a string that forms part of a valid identifier.
You probably want to either use an associative array,
declare -A n
n[${array[*]}]=$(arg_count ${array[*]})
or write your code in a programming language that properly supports data structures.

How to parse a word in shell script

I want to parse the following word in shell script
VERSION=METER1.2.1
Here i want to split it as two words as
WORD1=METER
WORD2=1.2.1
Let me help how to parse it?
Far more efficient than using external tools such is sed is bash's built-in parameter expansion support. For instance, if you want the name variable to contain everything until the first number, and the numbers variable to contain everything after the last alpha character:
version=METER1.2.1
name=${version%%[0-9]*}
numbers=${version##*[[:alpha:]]}
To understand this, see the BashFAQ entry on string manipulation in general, or the BashFAQ entry on parameter expansion in particular.

How to create variables in a template file in ruby?

I want to have a text template file that would contain variables.
the file is read
variables replaced with its values
the file is saved
I tried to have a file with #{my_variable} but actually the character # is escaped so #{my_variable} is not replaced with the value of the variable because it's text.
tried to escape # in the text file \# but it didn't work
Is there any way that I don't have to do search and replace in this scenario?
As clyfe mentioned, you should definitely be using ERB's for this:
http://www.rrn.dk/rubys-erb-templating-system/
This will let you use variables, loops, methods, etc. and is far more robust.

Resources