User Tools

Site Tools


myhelp:bash

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
myhelp:bash [2023/05/03 12:20] ulrichmyhelp:bash [2024/03/07 12:12] (current) ulrich
Line 1: Line 1:
-====== Read a file per line ====== +Read a file per line 
-<code># while read line; do echo "$line"; done < file.txt </code>+ 
 +``` 
 +# while read line; do echo "$line"; done < file.txt 
 +``` 
 + 
 +# Upper to Lower
  
-====== Upper to Lower ====== 
 Is pretty easy done Is pretty easy done
-<code># cat /path/to/file.txt|tr '[:upper:]' '[:lower:]'</code>+ 
 +``` 
 +# cat /path/to/file.txt|tr '[:upper:]' '[:lower:]' 
 +``` 
 or or
-<code># echo "LadiDA"|tr '[:upper:]' '[:lower:]'</code> 
  
-====== SED Examples ======+``` 
 +# echo "LadiDA"|tr '[:upper:]' '[:lower:]' 
 +``` 
 + 
 +SED Examples 
 Delete a line with a string in it. For example old ssh-keys: Delete a line with a string in it. For example old ssh-keys:
-<code># sed -i "/myuser@old.laptop/d"  .ssh/authorized_keys </code> 
  
-====== Calculate ======+``` 
 +# sed -i "/myuser@old.laptop/d"  .ssh/authorized_keys 
 +``` 
 + 
 +Calculate 
 You can use the expr You can use the expr
-<code># expr 1 + 2</code>+ 
 +``` 
 +# expr 1 + 2 
 +``` 
 and you will get 3 as result. and you will get 3 as result.
  
 Also some more fancy stuff is possible. For example in a for-loop: Also some more fancy stuff is possible. For example in a for-loop:
-<code>for i in {1..9}; do echo "10.20.30.$(expr $i + 40)   servername-$i"; done</code> 
  
-====== Bash redirection ======+``` 
 +for i in {1..9}; do echo "10.20.30.$(expr $i + 40)   servername-$i"; done 
 +``` 
 + 
 +Bash redirection 
 stdout to file stdout to file
-<code># command > file.txt</code>+ 
 +``` 
 +# command > file.txt 
 +```
  
 stderr to file  stderr to file 
-<code># command 2> /dev/null</code>+ 
 +``` 
 +# command 2> /dev/null 
 +```
  
 stdout AND stderr to file stdout AND stderr to file
-<code># command &> file.txt</code>+ 
 +``` 
 +# command &> file.txt 
 +```
  
 stdout to file AND stderr to file  stdout to file AND stderr to file 
-<code># command > file.txt 2> /dev/null</code>+ 
 +``` 
 +# command > file.txt 2> /dev/null 
 +```
  
 stdout to stderr stdout to stderr
-<code># command 1>&2</code>+ 
 +``` 
 +# command 1>&2 
 +```
  
 stderr to stdout stderr to stdout
-<code># command 2>&1</code> 
  
-{{tag>[Good2Know bash]}}+``` 
 +# command 2>&1 
 +```
  
  
myhelp/bash.1683116428.txt.gz · Last modified: by ulrich