I am following this tutorial to correctly execute Aptana Studio on my Ubuntu 14.04:
So I have installed the Oracle JRE and finnally I have create this run.sh
file that have to execute Aptana:
!/bin/bash
export UBUNTU_MENUPROXY=0 /home/andrea/Programmi/Aptana_Studio_3/AptanaStudio3
The problem is that when I try to execute this script with my shell I obtain the following error message:
andrea@andrea-virtual-machine:~/Programmi/Aptana_Studio_3$ sudo sh run.sh
run.sh: 1: run.sh: !/bin/bash: not found
run.sh: 3: export: /home/andrea/Programmi/Aptana_Studio_3/AptanaStudio3: bad variable name
Why? What am I missing? How can I fix this issue?
There are two errors. In short, this is the particular fix I would suggest (details follow):
Bad Hashbang Line
As Shutupsquare says, your hashbang line (technical details) should start with a
#!
rather than just!
.That is causing the first of your two error messages, and will prevent your script from being run as
./run.sh
, but is not the reason your script is failing to runAptanaStudio3
(because the hashbang line is not required forsh run.sh
calling syntax).By the way, when you run
sh run.sh
, it runs your script withsh
as the interpreter. But with the hashbang line#!/bin/bash
, running./run.sh
would run your script withbash
as the interpreter. This script does not in any way depend on the advanced features ofbash
, and whilebash
's additional memory usage is almost certainly insignificant for this application, you may still wish to write the hashbang line so./run.sh
runs the script withsh
:Incorrect Use of
export
The main problem, which is causing your second error message and is the reason
AptanaStudio3
fails to run, is that you're usingexport
incorrectly. Theexport
command does not run commands. So your command is being interpreted as an environment variable itself.export
can set and export an environment variable:export
can also export an environment variable (with whatever its current value is):export
does not acceptNAME=value command
orNAME command
syntax, however.Assuming your goal is to run the command
/home/andrea/Programmi/Aptana_Studio_3/AptanaStudio3
with theUBUNTU_MENUPROXY
variable defined and set to0
, you should just drop the wordexport
altogether:That is the standard way to run a command with a modified environment, from a shell.
The purpose of
export
is to export variables into the environments of all subsequently launched child processes (i.e., every command run from your script). So runningexport UBUNTU_MENUPROXY=0
on its own line followed by theAptanaStudio3
command, as Shutupsquare suggests, will work, and have the same effect, and is a perfectly good and acceptable way to do it.I prefer the way I've suggested above (without
export
) because:export
may cause confusion to others reading your script (or to yourself later), and as a secondary consideration is arguably less elegant.export
, you need two commands; using the way without it, you need only one.Optional reading: the
env
command works (sort of) the way you were trying to useexport
Finally, there is a command that accepts
NAME=value command
syntax. This command isenv
. There's no reason to use it in this shell script--its function, in that basic usage, is to provide (part of) the power of a shell in running a command with a modified environment, and you already have that power.However, under some circumstances, outside of shell scripting, you may find you need to set an environment variable for a command and run that command (and do those things in a single command). In contexts where just using the line
VARIABLE=value command
is not supported, you can use:You don't need that here though. All Bourne-style shells (e.g.,
sh
,dash
,bash
,ksh
,zsh
) supportVARIABLE=value command
.Should be
#!/bin/bash
. I also think that you should have a newline at the end ofexport UBUNTU_MENUPROXY=0
.