ops102:bash_scripting_1
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| ops102:bash_scripting_1 [2025/03/08 03:00] – [Setting a Variable] chris | ops102:bash_scripting_1 [2025/03/11 15:11] (current) – chris | ||
|---|---|---|---|
| Line 38: | Line 38: | ||
| The current date and time is: | The current date and time is: | ||
| Sat Mar 6 12:03:32 EST 2038 | Sat Mar 6 12:03:32 EST 2038 | ||
| + | |||
| + | ===== Comments ===== | ||
| + | |||
| + | A comment in a bash script starts with a sharp symbol (#) and is ignored by the shell interpreter: | ||
| + | |||
| + | < | ||
| + | # written by Jason Bourne</ | ||
| + | |||
| + | A comment may also be just one portion of a line: | ||
| + | |||
| + | < | ||
| + | |||
| + | Note that a shbang line is a comment from the point of view of the shell interpreter -- it's there for the kernel to use, not the shell! | ||
| ===== Variables ===== | ===== Variables ===== | ||
| Line 104: | Line 117: | ||
| Hello $B | Hello $B | ||
| - | You should always double-quote variables that may contain a space in their value when using them as command arguments. | + | You should always double-quote variables that may contain a space in their value when using them as command arguments. |
| + | |||
| + | Here is an example -- the difference between the first '' | ||
| - | This is especially true for filenames -- you never know when a user is going to put a space in a filename! Many scripts work find with opaque filenames (those containing no whitespace) but fail with non-opaque names. | + | $ touch "red maple" |
| + | |||
| + | $ FILE=" | ||
| + | |||
| + | $ ls $FILE | ||
| + | ls: cannot access ' | ||
| + | ls: cannot access ' | ||
| + | |||
| + | $ ls " | ||
| + | 'red maple' | ||
| === Backslashes === | === Backslashes === | ||
ops102/bash_scripting_1.1741402808.txt.gz · Last modified: 2025/03/08 03:00 by chris
