Category: Bash
-
A bash builtin command named “enable” to enable or disable a bash builtin command
[bash light=”true”] $command $echo $? 0 $enable -n command $command bash: command: command not found $echo $? 127 $enable command $command $enable -n enable $enable bash: enable: command not found $ [/bash] RELATED SOURCE CODE EXPOSURE [c light=”true”] /* Enable/disable shell commands present in LIST. If list is not specified, then print out a list […]
-
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 *** […]
-
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__ […]