How can I execute commands in a text file?

I have a bunch of commands seperated by \ns that I'd like to execute serially (from the command line) in a file called ec2-env-setup. I'd appreciate any help.


This is called a script.

Right click on the text file, select properties, select permission, mark the "Let this file be executed" text box. Now you can execute it just by double clicking on the file.

You can also do it from the console like this:

sh ec2-env-setup.

Or change the permissions and afterwards execute it:

chmod u+x ec2-env-setup.
./ec2-env-setup.

You need to make it excecutable:

chmod +x ec2-env-setup

And then run it (this will work if you are in the same directory as it, otherwise, use an absolute path).

./ec2-env-setup

Just for future reference, and to counter some of the command-line love going on here :-) you can also open the Properties of the file, select the Permissions pane and enable the Executable flags. If you then double-click the file, it'll let you run it as a script.

You might want to run it in the Terminal though if you'd like to see the output.

You can also create a Launcher. Right click on the Desktop and select Create Launcher to do that.


well i will answer my own question i posted here before and deleted as i found the answer. my file did not execute but just openend...

if file does not execute you might need to set preferences. for that: click any folder, go to menu edit, choose preferences,click behavior tab, check "run executable textfiles when they are opened". doubble click the file to execute...