User Tools

Site Tools


linux:bash

Differences

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

Link to this comparison view

Next revision
Previous revision
linux:bash [25/09/2024 15:20] – created - external edit 127.0.0.1linux:bash [10/09/2025 12:56] (current) – [for loop] andrew
Line 1: Line 1:
 ====== Bash ====== ====== Bash ======
 +
 +[[bash-quickguide|Quick guide to shell scripts in BASH]] \\
 +[[bash-quotes|BASH Quotes examples]] \\
 +[[bash-getoptions|BASH Get Options]] \\
 +[[bash-post-to-api|POST to API with cURL]] \\
 +[[bashshortcut|BASH references and shortcuts]] \\
 +[[bash-snippets|BASH Snippets]] \\
 +[[bash_aaart|Ascii Art]] \\
 +
 +[[misc-bash-cgi|BASH cgi Misc info]] \\
  
 **What is BASH?** **What is BASH?**
Line 20: Line 30:
  
 [[linux:bash-quickguide|Quick guide to shell scripts in BASH]] [[linux:bash-quickguide|Quick guide to shell scripts in BASH]]
 +
 ===== Generic script frameworks ===== ===== Generic script frameworks =====
  
Line 33: Line 44:
  
 [[linux:bashshortcut|Bash reference and shortcuts sheet]] [[linux:bashshortcut|Bash reference and shortcuts sheet]]
 +
 ==== Print tab character. ==== ==== Print tab character. ====
  
Line 57: Line 69:
 ==== Running multiple commands ==== ==== Running multiple commands ====
  
-Join two or more commands together, just rune them in turn and don't care if they succeed or fail:-+Join two or more commands together, just run them in turn and don't care if they succeed or fail:-
  
   $ command1 ; command2   $ command1 ; command2
Line 97: Line 109:
  
 Unlike setting variables where a space round the ''VARIABLE=value'' is required, comparison operators NEED a space round the operator, thinking on this, setting a variable and testing it are quite different operations, but the ''='' and ''=='' for variable setting and testing numeric equality do superficially look similar.  Unlike setting variables where a space round the ''VARIABLE=value'' is required, comparison operators NEED a space round the operator, thinking on this, setting a variable and testing it are quite different operations, but the ''='' and ''=='' for variable setting and testing numeric equality do superficially look similar. 
 +
 ===== if elif else ===== ===== if elif else =====
  
Line 156: Line 169:
   do   do
         echo "WebSite is ${VARIABLE}, acton is ${ACTION}"         echo "WebSite is ${VARIABLE}, acton is ${ACTION}"
 +  done
 +
 +
 +  subnets=
 +  subnet-02dc9fac8fd877129
 +  subnet-0f8b1423c13b2cd79
 +  subnet-049f0d086b3590d8b
 +
 +
 +  for subnet in ${subnets[@]}
 +  do
 +      echo "creating mount target in " $subnet
   done   done
  
Line 182: Line 207:
 ===== while loop ===== ===== while loop =====
  
-  while ($line = <SERIAL> +Multiline:
-  { + 
-      print "$line\n"; +  while [ condition ] 
-  +  do 
-  +    
 +      print "$SOMETHING\n"; 
 +    
 +  done 
 + 
 + 
 +On one line:- 
 +  while [ condition ]; do print "$SOMETHING\n"; done 
 + 
 ===== Time duration of operation and record exit status ===== ===== Time duration of operation and record exit status =====
  
Line 309: Line 343:
  
  
-===== Arrays =====+===== Arrays or Lists =====
  
 Bash array example, indices start at zero, so below [1] returns the second element ('example'):- Bash array example, indices start at zero, so below [1] returns the second element ('example'):-
linux/bash.1727277622.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki