Timeline for Bash: Assign output of pipe to a variable
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 24, 2022 at 9:32 | history | edited | Kusalananda♦ | CC BY-SA 4.0 | Fix quoting |
| Apr 24, 2022 at 8:09 | history | edited | Chris Davies | CC BY-SA 4.0 | deleted 51 characters in body |
| Apr 24, 2022 at 6:51 | comment | added | G-Man Says 'Reinstate Monica' | (Cont’d) … (2) @roaima is right: you should double-quote all your variables (e.g., complex_command > "$tmppath" and rm -f "$tmppath"), and you don’t need any of those curly braces. (3) You could improve this answer by testing whether mktemp succeeded before you use "$tmppath". | |
| Apr 24, 2022 at 6:51 | comment | added | G-Man Says 'Reinstate Monica' | (1) I’m giving you a +1 for posting the best answer, complete with mktemp and rm, even though Stéphane Chazelas posted the bare bones of that answer four years earlier. Please get into the habit of reading all the existing answers before you post a new one. It’s OK to post a new answer improving on a previous post (IMO, you did that), but you should cite any such previous posts. … (Cont’d) | |
| May 7, 2021 at 10:10 | history | edited | devildelta | CC BY-SA 4.0 | fix typo |
| May 7, 2021 at 6:56 | review | Late answers | |||
| May 10, 2021 at 7:29 | |||||
| May 7, 2021 at 6:56 | comment | added | Chris Davies | Shouldn't message=$(echo ${tmppath}) be message=$(cat "$tmppath") to get the contents of the temporary file rather then its name | |
| May 7, 2021 at 6:53 | comment | added | Chris Davies | Double-quote your variables when you use them so that their contents isn't parsed and word-split by the shell. For example echo $message should become echo "$message". (The curly braces are mostly unneeded.) Note that if $message begins with a dash (hyphen) all bets are off when you try to use echo anyway | |
| May 7, 2021 at 6:40 | review | First posts | |||
| May 21, 2021 at 6:36 | |||||
| May 7, 2021 at 6:35 | history | answered | devildelta | CC BY-SA 4.0 |