LINUXOPOLIS # 2019-10-27 ~ BASH

3개월 전

BASH

Published with SteemPeak
home ~ previous

ScreenshotScreenshot by Willi Glenz

SUMMARY

01 BASH ............................................................. v1 2019-05
06 shellcheck ....................................................... v1 2019-05

10 aliases .......................................................... v2 2019-06
09 job-control ...................................................... v1 2019-06
05 environment ...................................................... v1 2019-05
02 script-editor .................................................... v3 2019-05
07 tests ............................................................ v1 2019-05
18 if ............................................................... v1 2019-08
04 while-loop ....................................................... v1 2019-05
13 bash-to-fish|zsh ................................................. v1 2019-06
15 zsh .............................................................. v1 2019-06
16 dialog ........................................................... v1 2019-07
19 files ............................................................ v1 2019-10 new
03 ~/.bashrc ........................................................ v4 2019-06
08 ~/.bash_history .................................................. v1 2019-06
10 ~/.bash_aliases .................................................. v2 2019-06

11 bash-guide-for-beginners ......................................... v1 2019-06
12 advanced-bash-scripting-guide .................................... v1 2019-06
17 sources .......................................................... v1 2019-08



#19

19 FILES
$ cat /dev/null > file.txt ......................................................... empty a file
$ man null


18 IF-STATEMENT
if [ test ]
then
    commands
elif [ test ]
then
    commands
else
    commands
fi
ryanstutorials.net  : ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php#ifelif
gnu.org             : gnu.org/software/bash/manual/html_node/Conditional-Constructs.html#Conditional-Constructs


17 SOURCES
Bash-Documentation              : gnu.org/software/bash/manual/html_node/index.html
Bash-Beginners-Guide            : ldp.org/LDP/Bash-Beginners-Guide/html/index.html
Advances-Bash-Scripting-Guide   : tldp.org/LDP/abs/html/


16 DIALOG
install ................ # apt install dialog
hello world ............ $ dialog --title 'Message' --msgbox 'Hello world!' 5 20
file viewer ............ $ dialog --textbox ~/.bash_aliases 32 80

check-box .............. $ 
$ vim menu.sh
    #!/bin/bash
    # ~/bin/menu.sh
    # first steps
    # version 1
    MENU=`dialog --stdout --no-cancel --clear --menu "Check-Box" 14 20 7 1 one 2 two 3 three 4 four 5 five 6 six q quit`
    echo "Item: : $MENU"
:wq
$ chmod 744 ~/bin/menu.sh
Manpages        $ man dialog
Tutorial        : linuxjournal.com/article/2807


015 ZSH 
$ apt install zsh

OH-MY-ZSH
• github.com/robbyrussell/oh-my-zsh
$ sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
$ uninstall_oh_my_zsh
• MAN-Pages : $ man zsh
• FAQ       : zsh.sourceforge.net/FAQ/


13 BASH-TO-FISH|ZSH
$ grep -i user /etc/passwd
$ echo $SHELL
$ cat /etc/shells
# apt install fish zsh
$ cat /etc/shells

• Option 1: # vim /etc/passwd               
• Option 2: $ chsh -s /usr/bin/fish         
• Option 3: # usermod -s /bin/bash user     

$ chsh -s /usr/bin/fish
$ chsh -s /bin/fish

$ cat /etc/passwd | cut -d: -f7 | sort | uniq -c | sort -nr


12 ADVANCED-BASH-SCRIPTING-GUIDE
# apt search abs-guide
# apt show abs-guide
# apt install abs-guide
$ dpkg -L abs-guide
> file:///usr/share/doc/abs-guide/html/index.html
tldp.org/LDP/abs/html/


11 BASH-GUIDE-FOR-BEGINNERS
ldp.org/LDP/Bash-Beginners-Guide/html/index.html


10 ALIASES
$ alias
$ ls -l ~/.bash_aliases
$ cp ~/.bash_aliases ~/.bash_aliases_backup
$ alias > ~/.bash_aliases

$ vim ~/.bashrc
    if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
    fi
:wq

$ vim ~/.bash_aliases
   alias a='clear; echo; alias; echo'
   alias c='clear; neofetch; cowsay -W 131 -f moose $(cat ~/bin/oneliner.txt | shuf -n1); echo'
   alias cc='clear; ncal -wy'
   alias ea='vim ~/.bash_aliases && source ~/.bash_aliases'
   alias gl='clear; glances'
   alias gu='clear; guake &' 
   alias h='clear; echo; history 30; echo'
   alias i='intellij-idea-community &'
   alias l='clear; echo; lsd -l; echo'
   alias py='clear; python3'
   alias r='ranger'
   alias s='clear; curl rate.sx/steem@30d'
   alias sc='screen -S firstsession'
   alias ss='clear; curl rate.sx/steem@1d; gnome-screenshot -ac'
   alias ti='clear; tilda&' 
   alias tm='clear; timew month'
   alias tt='clear; task burndown.daily'
   alias ttt='clear; task calendar 2019'
   alias tw='timew'
   alias u='clear; sudo apt update && sudo apt upgrade && sudo apt dist-upgrade; sudo apt autoremove -yy'
   alias yt='sudo -H pip install --upgrade youtube-dl'
:wq


09 JOB-CONTROL
$ vim ~/.vimrc <ctrl+z>
$ vim ~/.bashrc <ctrl+z>
$ ranger <ctrl+z>
$ htop <ctrl+z>
$ glances &
$ jobs
$ fg 1

RUN A BACKGROUNd-JOB
$ sleep 10000 &
$ jobs -l
$ kill 12345

SOURCES
$ help jobs
$ help fg
$ help bg


08 HISTORY 
$ lsd -l | vim - -g ................................... vim


07 TESTS
STRINGS
$ [ StringA = StringB ];    echo $?
$ [ StringA != StringB ];   echo $?
$ [ -z String ];            echo $?
$ [ -n String ];            echo $?

NUMBERS
$ [ "$NUM" -eq 10 ];        echo $?
$ [ "$NUM" -neq 10 ];       echo $?
$ [ "$NUM" -gt 10 ];        echo $?
$ [ "$NUM" -ge 10 ];        echo $?
$ [ "$NUM" -lt 10 ];        echo $?
$ [ "$NUM" -le 10 ];        echo $?

$ [ -f fileName ];          echo $?
$ [ -d directory ];         echo $?
$ man test


06 SHELLCHECK
$ shellcheck ~/bin/script.sh


05 ENVIRONMENT
$ printenv | awk '/PATH|HOME|USER|SHELL/ {print $0}'


04 WHILE-LOOP 
#!/bin/bash
# while-loop 
# ~/bin/wl
# wl set `date`

[ -z "$1" ] && exit 1

echo "Command   : $0"
echo "Count Args: $#"

COUNTER=1
while [ -n "$1" ]
do
   echo "Argument ${COUNTER}: $1"
   shift
   COUNTER=`expr $COUNTER + 1`
done

exit


03 BASHRC
$ mkdir ~/bin
$ cp ~/.bashrc ~/.bashrc_old

$ vim ~/.bashrc
  HISTCONTROL=ignoreboth:erasedups
  HISTSIZE=1000
  HISTFILESIZE=1000
  if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
  fi
  set -o vi
  bind -m vi-insert "\C-l":clear-screen
  EDITOR=/usr/bin/vim
  VISUAL=$EDITOR
  export EDITOR VISUAL
  export PATH=$HOME/bin:$PATH
:wq


02 SCRIPT-EDITOR 
#!/bin/bash
# scripteditor
# ~/bin/ed
# ed scriptname.sh
 
[ -z "$1" ] && exit 1

DIR=~/bin/

vim "$DIR$1"
chmod 744 "$DIR$1"
clear; echo; lsd -l; echo

exit


01 BASH
SESSION

$ sudo !!
# apt-get update && apt-get upgrade && apt-get dist-upgrade; apt-get autoremove -yy
# init 0
# init 6
# shutdown -c
# shutdown -h 1:00
# shutdown -r now

SUDO

# visudo 
> Defaults:user timestamp_timeout=30
Homepage        : gnu.org/software/bash/
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
STEEMKR.COM IS SPONSORED BY
ADVERTISEMENT
Sort Order:  trending

This post had received 5.00% upvote from @steemitportugal account!
Our website has lots of news and tutorials you can visit right now at www.steemitportugal.com

Click here to vote
steemitportugal
Delegation for daily voting: 10SP-25SP-50SP-100SP-250SP-500SP-1000SP