In Windows I can write a file containing commands for cmd (usually .cmd
or .bat
files). When I click on those files it will open cmd.exe
and run them commands the file contains.
How would I do this in Ubuntu?
I'm sure this is a duplicate, but I can't find my answer.
Its similar to these questions, but they don't answer the question:
Best Answer
There are two methods.
First, the most common is to write a file, make sure the first line is
Then save the file. Next mark it executable using
chmod +x file
Then when you click (or run the file from the terminal) the commands will be executed. By convention these files usually have no extension, however you can make them end in
.sh
or any other way.A few notes:
/bin/python
,/bin/sh
,/bin/dash
, but even odd ball things work like/bin/mysql
bash file/to/run.sh
A Simple Bash Example
The second method is to record commands using
script
. Runscript
then just do stuff. When you are done doing stuff typeexit
and script will generate a file for you with all the "stuff" you did. This is less used but works quite well for making things like macros.man script
for more info.