Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What am I doing wrong in this script?


cat > /tmp/flash-viewer.htm <<- _EOF_
<object width=\"1280\" height=\"720\" data=\"$1\"></object>

if [ -n $BROWSER ]; then
  $BROWSER '/tmp/flash-viewer.htm'
elif which xdg-open > /dev/null; then
  xdg-open '/tmp/flash-viewer.htm'
elif which gnome-open > /dev/null; then
  gnome-open '/tmp/flash-viewer.htm'
  echo "Could not detect the web browser to use."

The script gives these errors:

joe@U13:~/Script$ ./ "/home/joe/video.swf"
/tmp/flash-viewer.htm: line 1: <HTML><HEAD><TITLE>Flash: command not found
/tmp/flash-viewer.htm: line 2: <object: command not found
/tmp/flash-viewer.htm: line 3: </BODY></HTML>: No such file or directory

Is there some kind of escape sequence I'm missing? I've already tried using \ to escape the LT/GT brackets and enclosing the html in single and double quotes. Each produces similar errors.

share|improve this question
What does $BROWSER actually evaluate to? it looks like your script is trying to execute the contents of the HTML file, rather than pass it as an argument to the command. – steeldriver May 23 '14 at 13:05
How are you trying to execute the script? You have not set the BROWSER variable anywhere, when is it set? – i08in May 23 '14 at 13:11
if works for me if I launch it with BROWSER=firefox ./ – Sylvain Pineau May 23 '14 at 13:12
up vote 5 down vote accepted

If $BROWSER is empty [ -n $BROWSER ] becomes just [ -n ]. That tests if -n has non-zero length, which is always true.

Then $BROWSER '/tmp/flash-viewer.htm' is executed which actually is just '/tmp/flash-viewer.htm' if $BROWSER is empty.


if [ -n "$BROWSER" ]; then

so that there's always a second argument.

To find out the exact path of your browser, use which <browser>, replacing <browser> with the browser you are trying to open the file with.

For example,

which firefox

would return /usr/bin/firefox, so you could do:

share|improve this answer
Or you can use Bash's double square brackets. Also, type -p is better than which (for one thing, it's a built-in). – Dennis Williamson May 23 '14 at 16:08
While this answer is insightful, it does not help me. The browser selection code was taken from another question on this site and it works for me. The problem lies with the "cat" statement (aka "Here document") not writing the html tags. – sienile May 23 '14 at 21:57
According to the error messages there are errors when running (not writing) /tmp/flash-viewer.htm. – Florian Diesch May 24 '14 at 1:04
Right you are. I removed the $BROWSER section of the if statement and xdg-open launched the file. Thanks. -- I had thought $BROWSER was a global system environment variable. ...Wonder why it worked in that other guy's script. – sienile May 24 '14 at 10:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.