I would like some criticism of the following bash fragment (for some odd reason the first hash line is not shown, I just now realise).
The purpose of the code is described later.
_t="/tmp/$$-remote-iPad-to-pi.XXXXXXXXXXXXX.bash"
printf "file_content" >"$_t"
chmod +x "$_t"
"$_t" 2>&1
rm "$_t" &
What I think I should be doing is adding the name (only) of the bash script, taken from argument 0 and I’ve seen an idiom for that, throwing away the path to just get the name but I forget. Is it basexxx something? So anyway I then also include that in the name of the temp file.
The real text of this bash script is generated at run time by an iOS Shortcuts program on the iPad which printf-escapes some text (with backslashes) and inserts that inline where I have put the placeholder file_content. It first removes all \ from the text, replacing each with a strange multi character escape which contains various extremely odd non-ascii characters, then takes all awkward characters and blackslash-prefixes them before undoing the first lot of damage replacing the weird escape with \\.
The idea of this is that the iPad generates a bash script sends it to the raspberry Pi (via ssh / IPv6) and then runs it. On the pi as you see, a temp file is created, marked as executable and is then run. I don’t want this temp file to name-clash with anything else hence the pid, but I don’t think that’s enough, I would think including the script name makes things slightly better but more importantly what about including the time of tempfile creation ?