Linux shell script tips

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 shell script tips

Linux date 7 days ago

[huupv@huupv devopsroles]$ date +"%Y-%m-%d" --date "-7 day"

The screen output terminal as below

Linux shell script tips date ago

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

Linux shell script tips url

Conclusion

Thought the article, How to use Linux shell script tips as above. I hope will this your helpful.

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

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