linux:bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux:bash [2022/02/10 09:35] – [Commands] mhlinux:bash [2022/02/28 14:54] (current) mh
Line 15: Line 15:
 Bash has **synchronous command execution** meaning it will execute commands one at a time and users cannot interact with bash while it is executing a command. Bash has **synchronous command execution** meaning it will execute commands one at a time and users cannot interact with bash while it is executing a command.
  
-Bash is **not a strict interpreter**. The discipline of writing clear, safe and precise code lies heavily upon the user.  
  
 <WRAP round important> <WRAP round important>
-**Don't write bad bash code.**+Bash is **not a strict interpreter**.  
 + 
 +**Beware of the ambiguity** we are used to while expressing ourselves with human languages. 
 + 
 +The **discipline of writing clear, safe and precise code** lies heavily upon the user.  
 + 
 +__**Don't write bad bash code.**__
 </WRAP> </WRAP>
  
Line 30: Line 35:
 Many command types are syntax sugar: their effect can be achieved differently, but they exist to make the job easier.  Many command types are syntax sugar: their effect can be achieved differently, but they exist to make the job easier. 
 </WRAP> </WRAP>
 +
 +==== Variables ====
 +
 +Before a command's name you can insert one or many ''var=value'' assignments. These variables will apply only to that one command.
  
 ==== Basic commands ==== ==== Basic commands ====
Line 36: Line 45:
  
 Bash performs a search using this name and looks for :  Bash performs a search using this name and looks for : 
-  *alias (first)+  *alias (before anything else)
   *functions   *functions
   *built-in commands   *built-in commands
Line 54: Line 63:
 $ echo $name $ echo $name
 john john
 +</code>
 +----
 +
 +=== type ===
 +
 +Displays information on a command, and where it is stored.
 +
 +//Note that the **type** command and the **which** program are different and give different outputs//
 +
 +**Example**
 +<code bash>
 +$ type ls
 +ls is aliased to 'ls -al'
 </code> </code>
 ---- ----
Line 97: Line 119:
  
 They can be a filename, a variable name, the name of a program or just a litteral. They can be a filename, a variable name, the name of a program or just a litteral.
 +
 +Multiple arguments can be used, separated by a blank space
 </WRAP> </WRAP>
  
Line 179: Line 203:
 There can be **no whitespace** around the = operator !  There can be **no whitespace** around the = operator ! 
  
-If a whitespace is required in the variable, use 'quotes to create a literal+If a whitespace is required in the variable, use 'single quotesto create a literal
 </WRAP> </WRAP>
  
Line 319: Line 343:
 As a result, both file descriptors are connected to the same stream. As a result, both file descriptors are connected to the same stream.
  
 +Be careful not to write something like ''$ ls -l a b >myfiles.ls 2>myfiles.ls'' as due to the way streams are handled they will most likely end up mixing up and garbling the file 'myfiles.ls'
 </WRAP> </WRAP>
  
Line 350: Line 375:
 To make a script out of a file containing bash commands, add a hashbang at the beginning of the file : To make a script out of a file containing bash commands, add a hashbang at the beginning of the file :
  
-This is a direct path to bash in many GNU/Linux distributions+This is a direct path to bash in many GNU/Linux distributions :
 <code bash> <code bash>
 #!/bin/bash  #!/bin/bash 
 </code> </code>
  
-This invokes the 'env' program giving bash as an argument explicitly asking 'env' to find the path to bash and return it. It is safer and more inclusive for covering more exotic distributions and other operating systems.+This rather more precise alternative invokes the 'env' program giving bash as an argument explicitly asking 'env' to find the path to bash and return it. It is safer and more inclusive for covering more exotic distributions and other operating systems :
 <code bash> <code bash>
 #!/usr/bin/env bash #!/usr/bin/env bash
  • linux/bash.1644482144.txt.gz
  • Last modified: 2022/02/10 09:35
  • by mh