Bash: Difference between revisions

From DWIKI
Line 29: Line 29:
[[Category: Scripting]]
[[Category: Scripting]]
[[Category: Programming]]
[[Category: Programming]]
==functions==
function foo() {
    echo $1 $2
  }

Revision as of 15:47, 30 May 2018

Tips and tricks

get first character of a string

FIRST=${STRING:0:1}

check if var contains substring

[[ $foo =~ .*sub.* ]]

move cursor

^b move back 1 char
^f move forward 1 char
alt-b move back 1 word
alf-f move forward 1 word

loops

loop through range of numbers

for i in {0..10};do echo $i;done


functions

function foo() {
   echo $1 $2
 }