0

How can I run something more simpler than:

echo date > tmp.html && firefox tmp.html && rm tmp.html

Is it possible to get the same without creating and deleting the tmp.html?

4
  • Seeing as it apparently serves no purpose, sure: just firefox a.html...
    – jasonwryan
    Oct 14, 2015 at 23:00
  • 1
    could you add a little bit about the end result/functionality you're shooting for? Oct 14, 2015 at 23:06
  • @jasonwryan, sorry, it's not a.html, but tmp.html in all cases. Oct 14, 2015 at 23:08
  • @user3276552: changed the command. It's not for showing date on firefox. It's just for calling my attention on the browser at certain time. The idea is to pipe the output of a command to firefox (or whatever browser). Oct 14, 2015 at 23:10

1 Answer 1

1

/tmp is cleared on boot, so you can do this

date > /tmp/date.html && firefox /tmp/date.html

if you want to open the result of any command in a browser, add this to your shell startup script

function open_in_browser {
  echo $@ > /tmp/temp.html
  firefox /tmp/temp.html
} 

and then you can call

$ open_in_browser `date`

alternatively, if you'd prefer a more secure approach with stdin and better styling, you can use this function instead

function stdin_to_browser {
    local tmpfile=`mktemp /tmp/command-output.XXXXX.html`
    cat - > ${tmpfile}
    sed -i -e '1{s#^#<pre>#;};${s#$#</pre>#;}' ${tmpfile}
    firefox ${tmpfile} 2> /dev/null
}

which would let you

ifconfig | stdin_to_browser

(this example uses @thrig's suggestion of mktemp)

1
  • Or consider mktemp to avoid potential /tmp security flaws...
    – thrig
    Oct 14, 2015 at 23:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .