Just started recalling shell scripting again and I thought it would be good the post those somewhere.
So I started with following hello world. Not the simplest script, but it doesnt contain complex stuff. this script contains,
- How to comment,
- Output values using echo,
- Execute some simple commands,
- Assign output of a command to a variable,
- print variable values using echo.
bash and sh are two different shells. Basically bash is sh, with more features and better syntax. Most commands work the same, but they are different.Bash (bash) is one of many available (yet the most commonly used) Unix shells. Bash stands for "Bourne Again SHell",and is a replacement/improvement of the original Bourne shell (sh).
.sh
is indicative of a script for the Bourne shell (sh
) or the Bourne Again shell (bash
), which is generally a superset of its predecessor.
.csh
is indicative of a script for the C shell (csh
), which, being a shell, is largely similar, but significantly different as soon as you start doing anything much more complex than running a series of static commands.Both shells are generally available on any POSIXy environment, and indeed both are often preinstalled, though
bash
(and its cousinsh
) are a little more ubiquitous in my experience.I say 'indicative' above, because the idea of a file extension doesn't technically exist and has no semantic or syntactical meaning. A file could be named
script.steve
ordocumentation.exe
orinclude.h
and still actually be a shell script. For more definitive confirmation, look at the first line of the file. For a script designed to be executed directly, it should start with a shebang line, which starts with an octothorpe (#
), a bang (!
), and the path to the executable which should run the script. For example:#!/usr/local/bin/bash
or
#!/usr/bin/python3
No comments:
Post a Comment