On 12/07/2019 09:00, Michael Dorrington wrote:

> * Event: Manchester Free Software's July Meeting
> * What: Chat on Programming

Hopefully the meeting helped people at least get an appreciation of
programming.

If you can type commands on the command line and use a text editor then
you can create a shell script.

In the simplest, you can just put the commands in a text file and run
them by doing:

bash your_file_with_commands

This is assuming you want bash to run the commands.

If you want things a bit more self-contained then add this as the first
line of the file:

#!/bin/bash

and make the file executable by "chmod'ing" the file:

chmod --changes u+x -- your_file_with_commands

Now you can do:

./your_file_with_commands

And if the script's directory is in your PATH then you can just type:

your_file_with_commands

Bash contains the ability to use variables, to do conditional branching
('if / then / elif / else / fi' and '[ ] / test'), loops, regex, arrays,
associative arrays (yes!) and so on.  Bash has had features continually
added to it which means some documentation on Bash programming doesn't
use the new features and non-updated installs of Bash might not have
certain features.

Some exercises:

1. What happens if the script is executable but doesn't have a #! line
at the top?
2. What could you have instead of /bin/bash in the #! line?

M.

-- 
FSF member #9429
http://www.fsf.org/register_form?referrer=9429
http://www.fsf.org/about
"The Free Software Foundation (FSF) is a nonprofit with a worldwide
mission to promote computer user freedom and to defend the rights of all
free software users."



Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Fsfe-uk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/fsfe-uk

Reply via email to