diff options
author | Steven <steven.vasilogianis@gmail.com> | 2021-06-05 16:59:47 -0400 |
---|---|---|
committer | Steven <steven.vasilogianis@gmail.com> | 2021-06-05 16:59:47 -0400 |
commit | e68dac90a94e94027cf3385ce6aabe1e604dec26 (patch) | |
tree | 523d34abcbb86649522f23daa812cdbd7decadfd | |
parent | e901ffedb3545abe2d10a5049ccd72111beeac47 (diff) |
store output in variable
-rwxr-xr-x | shopenscad.sh | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/shopenscad.sh b/shopenscad.sh index c008c4e..96eaf0e 100755 --- a/shopenscad.sh +++ b/shopenscad.sh | |||
@@ -1,12 +1,9 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | |||
3 | # parse a .scad file and generate an openscad command with all its var=value's | 2 | # parse a .scad file and generate an openscad command with all its var=value's |
4 | # parameterized into -D options | 3 | # parameterized into -D options |
5 | 4 | ||
6 | |||
7 | openscad=${OPENSCAD:-"openscad"} | 5 | openscad=${OPENSCAD:-"openscad"} |
8 | 6 | scad_file=${1:-"Enter an input .scad file"} | |
9 | scad_file="$1" | ||
10 | 7 | ||
11 | function strip_comments () { | 8 | function strip_comments () { |
12 | strip_multiline_comments | 9 | strip_multiline_comments |
@@ -63,6 +60,7 @@ function shopenscad () { | |||
63 | input_file="$1" | 60 | input_file="$1" |
64 | output_params="" | 61 | output_params="" |
65 | output_filename="" | 62 | output_filename="" |
63 | output_sh="" | ||
66 | while IFS= read -r line; do | 64 | while IFS= read -r line; do |
67 | [ "$line" ] || continue; | 65 | [ "$line" ] || continue; |
68 | clean="$(echo -n "$line" |chomp)" | 66 | clean="$(echo -n "$line" |chomp)" |
@@ -70,15 +68,14 @@ function shopenscad () { | |||
70 | val=$(echo -n "$clean" |parse_value |chomp) | 68 | val=$(echo -n "$clean" |parse_value |chomp) |
71 | if [ "$var" ] && [ "$val" ]; then | 69 | if [ "$var" ] && [ "$val" ]; then |
72 | output_params+="-D '$var=$val' " | 70 | output_params+="-D '$var=$val' " |
71 | output_sh+="${var}=${val}\n" | ||
73 | output_filename+="$(val_to_filename "$val")-" | 72 | output_filename+="$(val_to_filename "$val")-" |
74 | fi; | 73 | fi; |
75 | done < <(echo "$(cat "$input_file")" | | 74 | done < <(echo "$(cat "$input_file")" | |
76 | strip_comments |strip_nonassignments |strip_trailing_semicolon) | 75 | strip_comments |strip_nonassignments |strip_trailing_semicolon) |
77 | 76 | ||
78 | echo "$openscad "$scad_file" "$output_params" -o $(strip_last_char "$output_filename").stl" | 77 | openscad_str="$openscad "$scad_file" "$output_params" -o $(strip_last_char "$output_filename").stl" |
78 | echo ${openscad_str} | ||
79 | } | 79 | } |
80 | 80 | ||
81 | shopenscad "$scad_file" | 81 | shopenscad "$scad_file" |
82 | |||
83 | |||
84 | |||