Quantcast
Channel: Manfaat Sehat
Viewing all articles
Browse latest Browse all 61

Bash Functions for more a powerful Alias

$
0
0
In ~/.bashrc you may should have some aliases set up which permit your commandline-fu to save you some time.  For example, these aliases help me on the daily:

  alias cifs='ssh root@10.10.10.208
  alias locate='locate -i '
    ## Low-quality remote desktop:

  alias lrdesktop='rdesktop -u Administrator -g 1140x840 -a8 -P -z -b -C'
   alias ls='ls --color=auto'
   alias mc='mv '

   alias vmi='vim '


If you want to use command-line variables, however, you cannot use Aliases.  This is where Functions come into play; you define the function and the actions it should take, substituting the commandline variables, and then export that function for use elsewhere if needed:

  ## Host command against Google's DNS 8.8.8.8
  function ghost { host "$1" 8.8.8.8;}
  export -f ghost



Now, the first commandline variable would substitute for $1, so:
   shell#  ghost nytimes

becomes
   shell#  host nytimes.com 8.8.8.8

Very slick for those repetitive tasks.  Note, and changes to the ~/.bashrc file requires that you reload bash or log out and log back in!



As an additional tip, install the package 'bash-completion' for better [tab][tab] completion and then add these lines to your ~/.bashrc file:

   if [ -f /etc/bash_completion ]; then
   . /etc/bash_completion
   fi




And to prevent duplicate items in your bash history, add these:

   export HISTCONTROL=ignoredups
   export HISTCONTROL="ignoreboth"
   export HISTIGNORE="&:ls:[bf]g:exit"shopt -s histappend
   PROMPT_COMMAND='history -a'

Viewing all articles
Browse latest Browse all 61

Trending Articles