cancel
Showing results for 
Search instead for 
Did you mean: 
ricardodacosta
Moderator
Moderator
  • 6,829 Views

Configuring your shell environment

Hey everyone!

I'd like to start a thread learning about your favourite RHEL bash tweaks. I'm particularly interested in:

  • Aliases
  • Shell environment variables
  • Functions

I'll get started:

Aliases:

 

 

alias apsc="ansible-playbook --syntax-check"

 

 

Shell environment variables:

 

 

export LESS="-X"

 

 

This will cause a pager to not clear on exit. For example, when you're reading a man page, the screen will be cleared on exit so if you have a man page which has examples that you'd like to immediately use in your current terminal, exiting the man page will keep your example onscreen.

Functions:

 

 

mcd(){
mkdir -pv $1
cd $1
}

 

 

using mcd foo will create a directory and then change into it.

I have many examples that I can share but I want to hear from you and I will share my full environment configuration that I use. My objective is to take the very best contributions and add them to my git repo for everyone to use. 

Labels (5)
15 Replies
Trevor
Starfighter Starfighter
Starfighter
  • 1,645 Views

Okay, here's my contribution to the original post.  In
keeping with my rant on "Shell" vs "Environment"
variables, 

When I'm covering variables in the shell environment,
i'm using the env, printenv, export, and set commands
to demonstrate things involving these variables.  

We know that the env, priintenv, and export commands
do not display/list shell variables - ONLY environment
variables.  The set command to the rescue!  Well, the
set command displays everything but the kitchen sink -
shell,variables, environment variables, and functions.

So first, I have them to simply execute the set command
without any options, so that they can see the additional
information that the env and printenv commands do not
display/list.  Of course, the focus is on the Shell variables.

Because the information displayed by the set command
can be a little overwhelming with the inclusion of functions
in the output, I show the students this little concoction, so
that the only information output will be Shell and Environment
variables:

$   set  -o  posix

I don't get into the details of what POSIX is all about.  I only
go as far as to explain that the command eliminates the display
of the functions when the set command is executed as shown. 
So now, each time they execute the set command, the only info
that is output is the names and values of Shell and Environment
variables.

Of course, there will be that one forward thinking person who
wants to know how to go about reverting back to a state whereby
the function names in the environment can once again be
displayed. I'll then serve up the following command:

$   set  +o  posix

Once that command has been executed, they can see
once again that executing the set command without any
options will display Shell variables, Environments variables,
and functions.  However, I don't stop there.  I take the 
opportunity to expose them to subshells, by letting them
see how that posix feature can be activated temporarily,
to prevent the display of functions when executing the
set command, by showing them this little concoction:

$  (set  -o  posix;  set)

After executing that command, they will see that the 
function names are not displayed, and if the set
command is executed as it was previously, the function
names do indeed appear.  Executing that little construct

                 (set -o posix; set)

did not impact the current shell environment, while
suppresing the display of functions in the output.

What's the BASH tweak in all of this?  As it
relates to Shell and Environment variables:

1)   set -o posix

 and

2)   (set -o posix; set)


I don't impose the details of why the tweak does what it
does, because that would take away from what the intent
of the tweak is to allow them to focus on/  What's being
featured is:  Shell vs Environment variables.  Also, I think
it might be a little bit much for students undertaking an
inaugural Linux course.

Trevor "Red Hat Evangelist" Chandler
rplueckh
Mission Specialist
Mission Specialist
  • 1,611 Views

I think the best enhancement in bash functionality is to install the bash-completion package to get tab autocompletion for many commands.

TM
Flight Engineer Flight Engineer
Flight Engineer
  • 1,562 Views

I cannot really work on my laptop without the below.in ~/.bash_profile
export HISTTIMEFORMAT='%F %T '
export HISTSIZE=1000000
export HISTCONTROL=ignoreboth

0 Kudos
Trevor
Starfighter Starfighter
Starfighter
  • 1,553 Views

Dang TM,

HISTSIZE=1000000.   Watcha got goin' on with 
that laptop

HISTTIMEFORMAT='%F %T ' and
HISTCONTROL=ignoreboth, okee dokee.

HISTSIZE=1000000      Ooooo   Weeeee

 

Trevor "Red Hat Evangelist" Chandler
0 Kudos
Armann
Flight Engineer
Flight Engineer
  • 1,530 Views

Great Scott! Let's step into the Delorean...

export HISTSIZE=1000000

Going back to the dawn of Unix time?

 

 

 

0 Kudos
dafydd
Cadet
Cadet
  • 1,015 Views

Add an archive function to ~/.bashrc that uses $( stat ) to pick out the last modified time to use as the backup file suffix. Inspired by https://www.commandlinefu.com/commands/view/24622/create-backup-copy-of-file-adding-suffix-of-the-da...

```

fn_archive () {
local df_target=${1:-}
 
if [ ! -z "${df_target}" ]
then
local s_lastmod=$( stat -c '%Y' ${df_target} )
local s_datestamp=$( date -d @${s_lastmod} "+%Y%m%d_%H%M%S" )
 
cp -pv ${df_target} ${df_target}.${s_datestamp}
fi

}

0 Kudos
Join the discussion
You must log in to join this conversation.