Scripting Classroomnotes 02/Feb/2023

User Shell

Setting up the user shell

  • PS1
    • In the home directory we have file called as .bashrc
    • .bashrc is a configuration file in Linux that contains commands and setings specific to the bash shell. This is executed every time a new bash shell is launched.
    • This can be used to set environmental variables, aliases and other shell customizations
    • backup the existing bashrc file cp ~/.bashrc ~/bashrc.tmp
    • open the bashrc and find PS1
    • Lets change this to PS1="QTDevOpsPrompt> "
    • Lets change PS1 PS1="\u@\H> \A "
    • Refer Here for the PS1 possibilities
    • Shell variable PS1 can be used to customize look and feel of our shell.
    • PS1 is called as primary prompt display variable
  • Alias
    • Lets add the following statements in the bash rc file
      alias proc="ps auwwx"
      alias pfilter="ps auwwx | grep"
      alias start="systemctl start "
      alias stop="systemctl stop "
      alias enable="systemctl enable "
    • proc = list of all processes
    • to filter the process according to keyword
    • Now apply and execute
  • Adjust the Bash history
    • In the bash rc file as shown in the highlighted section below
    • Bash shell remembers 1000 typed commands in history in the current session and to save more than 2000 commands in the history file called .bash_history
  • Adjust the PATH variable
    • We can edit the ~/.profile and PATH for the current user
  • SPECIAL VARIABLES in bashrc
    • PS1, PS2, PS3 and PS4
    • HISTSIZE, HISTFILESIZE
    • OLDPWD
    • PWD
  • Refer Here for all the variables and Refer Here for Shell initialization files

Writing our first shell script

  • Lets write a script which prints Hello, Shell Scripting
  • add execute permissions sudo chmod +x <filename>.sh
  • cheatsheet Refer Here
  • Refer Here for official docs
  • Refer Here for how to get a shell script to actually work.

Note

  • Lab Environment:
    • ubuntu 20.04
    • centos 8
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Plugin for Social Media by Acurax Wordpress Design Studio

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%