Category: Bash

finding source code or source file of a typical bash function

$type -a signals bash: type: signals: not found $type -a _signals _signals is a function _signals () { local -a sigs=($( compgen -P “$1” -A signal “SIG${cur#$1}” )); COMPREPLY+=(“${sigs[@]/#${1}SIG/${1}}”) } $declare -F _signals _signals $shopt -s extdebug $declare -F _signals _signals 862 /usr/share/bash-completion/bash_completion $declare -F _command _command 1732 /usr/share/bash-completion/bash_completion $declare -F compgen $declare -F _grub_dirs

caller — returns the context of any active subroutine call

$cat test.bash!/bin/bash die() { local frame=0 while caller $frame; do ((frame++)); done echo “$*” exit 1 } f1() { die “*** an error occured ***”; } f2() { f1; } f3() { f2; } f3 $ $bash test.bash 12 f1 test.bash 13 f2 test.bash 14 f3 test.bash 16 main test.bash *** an error occured ***

sort – sort lines of text files

$cat test.txt sept aug jan dec oct apr feb mar11 mar1 $sort test.txt apr aug dec feb jan mar1 mar11 oct sept $sort -M test.txt jan feb mar1 mar11 apr aug sept oct dec $

fold: Wrap input lines to fit in specified width

$cat test.pl use strict; use File::Rename (); use Pod::Usage; main() unless caller; sub main { my $options = File::Rename::Options::GetOptions or pod2usage; mod_version() if $options->{show_version}; pod2usage( -verbose => 2 ) if $options->{show_manual}; pod2usage( -exitval => 1 ) if $options->{show_help}; @ARGV = map {glob} @ARGV if $^O =~ m{Win}msx; File::Rename::rename(\@ARGV, $options); } sub mod_version { print __FILE__

pr – convert text files for printing

The following shows a command line session with pr command which helps in displaying contents of a file in shell scripts. $cat lkg.txt A for Apple B for Ball C for Cat D for Donkey E for Elephant F for Fox G for Goat H for Horse I for Insect $pr -l 10 lkg.txt A

What does true and false commands do ?

commandline session $true $true $? $echo $? 0 $false $echo $? 1 $echo $? 0 $echo $? 0 $false ; true $echo $? 0 $true ; false ; echo $? 1 $true ; false ; echo $? 1 $true ; false ; echo $? 1 $true ; false ; echo $? ; echo $? 1

script — make typescript of terminal session

STITCHED (C) FROM : Virtual Terminals commandline session $script Script started, file is typescript $ls Algorithms bookmark config-files firewall kernel_start.asm loader scripts animation books debian GD kernel_start.s Mail test art.text bugs-general debian-howtos jeffrin language ovlfose typescript beautifulwork cairo Docs kernel linux README web.application $ls -a . beautifulwork config-files GD kernel_start.s ovlfose web.application .. bookmark debian

common network utilities/tools

commandline session $ping www.beautifulwork.org PING beautifulwork.org (46.22.210.18) 56(84) bytes of data. 64 bytes from mars.infoclub.in (46.22.210.18): icmp_req=1 ttl=53 time=310 ms 64 bytes from mars.infoclub.in (46.22.210.18): icmp_req=2 ttl=53 time=210 ms 64 bytes from mars.infoclub.in (46.22.210.18): icmp_req=3 ttl=53 time=210 ms 64 bytes from mars.infoclub.in (46.22.210.18): icmp_req=4 ttl=53 time=210 ms 64 bytes from mars.infoclub.in (46.22.210.18): icmp_req=5 ttl=53 time=211