Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Bash Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Bash Cookbook

Bash Cookbook

By : Brash, Ganesh Sanjiv Naik
1 (1)
close
close
Bash Cookbook

Bash Cookbook

1 (1)
By: Brash, Ganesh Sanjiv Naik

Overview of this book

In Linux, one of the most commonly used and most powerful tools is the Bash shell. With its collection of engaging recipes, Bash Cookbook takes you through a series of exercises designed to teach you how to effectively use the Bash shell in order to create and execute your own scripts. The book starts by introducing you to the basics of using the Bash shell, also teaching you the fundamentals of generating any input from a command. With the help of a number of exercises, you will get to grips with the automation of daily tasks for sysadmins and power users. Once you have a hands-on understanding of the subject, you will move on to exploring more advanced projects that can solve real-world problems comprehensively on a Linux system. In addition to this, you will discover projects such as creating an application with a menu, beginning scripts on startup, parsing and displaying human-readable information, and executing remote commands with authentication using self-generated Secure Shell (SSH) keys. By the end of this book, you will have gained significant experience of solving real-world problems, from automating routine tasks to managing your systems and creating your own scripts.
Table of Contents (10 chapters)
close
close

Improving your shell – GCC and command line colors


In this recipe, we are going learn how a user can improve the shell. We will do this using the PS1 bash environment variable.

Getting ready

Besides a terminal, you need basic knowledge of PS1.

 

How to do it...

The terminal appearance is taken by the PS1 shell variable. The content allowed in PS1 will contain backslash-escape special characters.

First, we will see what PS1's current contents in the system. For that, run the following command:

$ echo $PS1

Here are the backslash-escape special characters:

  • \u: Current username
  • \h: Hostname
  • \W: Current working directory
  • \$: Will display # if the user is root; otherwise it will display $ only
  • \@: Current time in 12-hour AM/PM format

Now, we will modify our Bash. Run the following command:

$ PS1="[\\u@\\h \\W \\@]\\$"

Now, we will write a command to change the colors.

To make the text color blue, run the following command:

$ PS1="[\\u@\\h \\W \\@]\\$\\e[0;34m"

 

 

Now we, will see the tput command. Run the following...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY