How to Write Scripts in Ubuntu
Unix-like operating systems (in particular, Linux) always support one or more command-line interfaces or "shells." Each shell is a fully-featured programming language. You can write scripts using that programming language; scripts will be executed by the shell. Shell scripts are very portable -- all Linux machines have at least one shell installed -- and useful to automate repetitive programming and system administration tasks. You can write and execute scripts on your Ubuntu Linux computer.
Instructions
-
-
1
Press "Control+Alt+F1" at the Ubuntu login prompt to bring up a text-mode login prompt. Log in by entering your username and password. Ubuntu will present you with a shell awaiting your commands.
-
2
Launch a text editor to create a new file named "myScript.sh". The file will contain the code for the shell script.
-
-
3
Substitute "/bin/bash" with the full path to the shell of your choice. The shell must be already installed on the Ubuntu computer.
-
4
Insert the code for the shell script using the text editor, as in the following example:
find ~ -name "*.pdf"
This sample script will list all PDF files currently stored under your home directory. Replace it by the lines of shell code required by your script, as per the shell's "Reference Manual." Save the file and exit the text editor.
-
5
Type the following command into the shell:
chmod u+x myScript.sh
Press "Enter." After executing the "chmod" command, the shell script will be ready to execute.
-
6
Execute the script by typing the following command into the shell:
./myScript.sh
Press "Enter."
-
1