In this tutorial, How do I use Linux shell script tips? shell script the essential for DevOps Roles.
Linux shell script tips
Load any functions file into the current shell script or a command prompt.
# source command source ~/.bashrc # or . . ~/.bashrc
Do not display output on terminal
[huupv@huupv devopsroles]$ echo devopsroles > /dev/null 2>&1
To display the time in the upper right corner on the terminal
[huupv@huupv devopsroles]$ while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-30));date;tput rc;done &
The screen output terminal as below
Linux date 7 days ago
[huupv@huupv devopsroles]$ date +"%Y-%m-%d" --date "-7 day"
The screen output terminal as below
Waiting for background processes to finish
[huupv@huupv devopsroles]$ sleep 100 & wait $!
Positional parameters in Linux
[huupv@huupv devopsroles]$ foo=(dev ops COM)
[huupv@huupv devopsroles]$ echo ${foo[2]:0}
>COM
Handling arrays in the shell script
[huupv@huupv devopsroles]$ foo=(x y z) [huupv@huupv devopsroles]$ echo ${foo[2]} >z [huupv@huupv devopsroles]$ echo ${#foo} >1
URL tips
[huupv@huupv devopsroles]$ url=https://www.devopsroles.com/huupv
If you want to retrieve user
$ echo ${url##*/}
> huupv
Retrieve the domain
[huupv@huupv devopsroles]$ echo ${url%/*}
> https://www.devopsroles.com
You want to retrieve the protocol
[huupv@huupv devopsroles]$ echo ${url%%/*}
> https:
The screen output terminal as below
Conclusion
Thought the article, How to use Linux shell script tips as above. I hope will this your helpful.