bash - mktemp with extension without specifying file path -


prefacing found identical questions none of them have answers working me.

i need make temporary .json file (it needs json because i'll working jq later in script).

i thought based on answers this question following, they're creating files named .json , xxxxxxxx.json respectively.

stacks=$(mktemp .json) stacks=$(mktemp xxxxxxxx.json) 

this need run on both mac os, , linux box. i can't specify path file because run both locally , jenkins, have unidentical file structure. what's proper syntax?

if using openbsd mktemp can

stacks="$(mktemp xxxxxx).json" 

and write trap tmps removed when script finishes:

function cleanup {     if [ -f "$stacks" ] && [[ "$stacks" =~ ".json"$ ]];         rm -f "$stacks"     fi } trap cleanup exit 

so when script finishes (no matter how) try remove $stacks if file , if ends .json (for safety).


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -