SlideShare a Scribd company logo
#!/bin/bash
# /usr/local/bin/mkscript
# Copyright 2000, Chris F.A. Johnson
# Released under the terms of the GNU General Public License
# USAGE: mkscript command
# fix permissions for script "command"-sh in /usr/local/bin/scripts
# create it if it doesn't exist
# link it to "command" in /usr/local/bin
die()
{
exitcode=$1
shift
if [ "$*" ]
then
echo "$*"
fi
exit ${exitcode:-1}
}
version() {
echo $version
}
usage()
{
echo "
$progname -
USAGE: $progname [OPTIONS]
OPTIONS:
-d DESC - description
-f - force=1 ;; # replace file if it exists
-r - remove=1 ;; # remove script if is exists
-R - remove=2 ;; # not used
-a OPTS - options that take arguments
-o OPTS - options that do not take arguments
-u - user=$OPTARG ;;
-a OPTS - argopts=$OPTARG ;;
-h - help: print this message
-H - help: print more detailed message
-v - verbose:
-V - print version information
Copyright 2001, Chris F.A. Johnson
"
}
put_header()
{
echo "#!/bin/bash
# `date`
# NAME: $command
# Copyright `date +%Y`, $author
# Released under the terms of the GNU General Public License
"
}
func_die()
{
echo 'die() {
exitcode=$1
shift
if [ "$*" ]
then
echo "$*"
fi
exit ${exitcode:-1}
}
'
}
func_version()
{
echo 'version()
{
echo " $progname, version $version
Copyright $copyright, $author $email
This is free software, released under the terms of the GNU General
Public License. There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
"
}
'
}
func_usage()
{
echo "usage()
{
echo " $progname - $description
USAGE: $progname [OPTIONS]
OPTIONS:
""
{
n=0
while [ $n -lt ${#argopts} ]
do
l=${argopts:$n:1}
echo " -$l arg - "
n=$(( $n + 1 ))
done
n=0
while [ $n -lt ${#opts} ]
do
l=${opts:$n:1}
echo " -$l - "
n=$(( $n + 1 ))
done
} | sort
echo "
[ $longusage -eq 1 ] &&
echo "
-h - help: print shorter help message
-H - help: print this message" ||
echo "
-h - help: print this message
-H - help: print more detailed message"
echo " -v - verbose:
-V - print version information
"
[ $longusage -eq 1 ] &&
version ||
echo "
Copyright $copyright, $author
"
}
"
}
put_vars()
{
echo "
description="$description"
verbose=0
longusage=0
version="1.0"
copyright=$copyright
author="$author""
echo 'progname=${0##*/}'
}
put_getopts()
{
[ -n "$argopts" ] && {
o=0
while [ $o -lt ${#argopts} ]
do
l=${argopts:$o:1}
[ "$l" ] && getopts="$getopts${NL} $l) ${l}_arg=$OPTARG ;;"
optstr=${optstr}${l}:
o=$(( $o + 1 ))
done
}
[ -n "$opts" ] && {
o=0
while [ $o -lt ${#opts} ]
do
l=${opts:$o:1}
[ "$l" ] && getopts="$getopts${NL} $l) ${l}_opt=1 ;;"
optstr=${optstr}${l}
o=$(( $o + 1 ))
done
}
echo "
while getopts vVhH-:$optstr var
do
case $var in"
echo "$getopts" | sort
echo '
-) case $OPTARG in
help) usage; exit ;;
help_long) longusage=1; usage; exit ;;
version) version; exit ;;
esac
;;
h) usage; exit ;;
H) longusage=1; usage; exit ;;
v) verbose=$(( $verbose + 1 )) ;;
V) version; exit ;;
*);;
esac
done
shift $(( $OPTIND - 1 ))
'
}
bindir="/usr/local/bin"
shdir="${bindir}/scripts"
version="1.1"
verbose=0
force=0
remove=0
longusage=0
progname=${0##*/}
NL=$'n'
while getopts vVhHfro:a:d:u: var
do
case "$var" in
d) description=$OPTARG ;;
f) force=1 ;; # replace file if it exists
r) remove=1 ;;
R) remove=2 ;;
a) argopts=$OPTARG ;;
o) opts=$OPTARG ;;
u) user=$OPTARG ;;
a) argopts=$OPTARG ;;
v) verbose=$(( $verbose + 1 )) ;;
V) version; exit ;;
h) usage; exit ;;
H) longusage=1; usage; exit ;;
*);;
esac
done
shift $(( $OPTIND - 1 ))
echo *=$*
echo opts=$opts
echo argopts=$argopts
if [ ! "$1" ]
then
die 1 "${progname}: command name required"
fi
cd ${shdir}
command=${1}
shcommand=${command}-sh
author="`grep -w ^$USER /etc/passwd | cut -d: -f5 | cut -d "," -f1`"
copyright=`date +%Y`
if [ $remove -ge 1 ]
then
if [ -f "$shcommand" -a $remove -eq 2 ]
then
rm -f $shcommand
fi
if [ -f $bindir/$command ]
then
rm -f $bindir/$command
fi
## add code to remove any other aliases in /usr/local/bin
exit
fi
if [ ! -f $bindir/$command ]
then
touch $shdir/$shcommand
cd $bindir
ln -s $shdir/$shcommand $command
fi
if [ -f "$shcommand" -a $force = 0 ];then
echo " $shcommand already exists
Use -f to replace it"
exit
fi
(
put_header
func_version
func_usage
put_vars
{
[ -n "$argopts" ] && {
echo $argopts | while read -n1 l
do
[ "$l" ] && echo "${l}_arg="
done
}
[ -n "$opts" ] && {
echo $opts | while read -n1 l
do
[ "$l" ] && echo "${l}_opt=0"
done
}
} | sort
put_getopts
) > ${shdir}/$shcommand
chown ${user:-$USER} ${shdir}/$shcommand
chmod a+x ${shdir}/${shcommand}
cd $bindir
pwd
ln -fs scripts/$shcommand $command
ls -l ${shdir}/$shcommand
if [ $remove -ge 1 ]
then
if [ -f "$shcommand" -a $remove -eq 2 ]
then
rm -f $shcommand
fi
if [ -f $bindir/$command ]
then
rm -f $bindir/$command
fi
## add code to remove any other aliases in /usr/local/bin
exit
fi
if [ ! -f $bindir/$command ]
then
touch $shdir/$shcommand
cd $bindir
ln -s $shdir/$shcommand $command
fi
if [ -f "$shcommand" -a $force = 0 ];then
echo " $shcommand already exists
Use -f to replace it"
exit
fi
(
put_header
func_version
func_usage
put_vars
{
[ -n "$argopts" ] && {
echo $argopts | while read -n1 l
do
[ "$l" ] && echo "${l}_arg="
done
}
[ -n "$opts" ] && {
echo $opts | while read -n1 l
do
[ "$l" ] && echo "${l}_opt=0"
done
}
} | sort
put_getopts
) > ${shdir}/$shcommand
chown ${user:-$USER} ${shdir}/$shcommand
chmod a+x ${shdir}/${shcommand}
cd $bindir
pwd
ln -fs scripts/$shcommand $command
ls -l ${shdir}/$shcommand

More Related Content

What's hot

Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
brian d foy
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
Ben Pope
 
spug_2008-08
spug_2008-08spug_2008-08
spug_2008-08
colinmeyer
 
Advanced Shell Scripting
Advanced Shell ScriptingAdvanced Shell Scripting
Advanced Shell Scripting
Alessandro Manfredi
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helper
slicejack
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - phpHung-yu Lin
 
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlinYahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
Shoichi Matsuda
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
Lingfei Kong
 
My First Ruby
My First RubyMy First Ruby
My First Ruby
Murray Steele
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
brian d foy
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
Vic Metcalfe
 
Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
Chhom Karath
 
Perl Fitxers i Directoris
Perl Fitxers i DirectorisPerl Fitxers i Directoris
Perl Fitxers i Directoris
frankiejol
 
Simplifying code monster to elegant in n 5 steps
Simplifying code  monster to elegant in n 5 stepsSimplifying code  monster to elegant in n 5 steps
Simplifying code monster to elegant in n 5 steps
tutec
 
Oo Perl
Oo PerlOo Perl
Oo Perl
olegmmiller
 
MuseScore MusicHackDay Presentation
MuseScore MusicHackDay PresentationMuseScore MusicHackDay Presentation
MuseScore MusicHackDay Presentation
MuseScore
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)GroovyPuzzlers
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
David Golden
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basicsAbhay Sapru
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
Quỳnh Phan
 

What's hot (20)

Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
 
spug_2008-08
spug_2008-08spug_2008-08
spug_2008-08
 
Advanced Shell Scripting
Advanced Shell ScriptingAdvanced Shell Scripting
Advanced Shell Scripting
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helper
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - php
 
Yahoo! JAPANとKotlin
Yahoo! JAPANとKotlinYahoo! JAPANとKotlin
Yahoo! JAPANとKotlin
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本
 
My First Ruby
My First RubyMy First Ruby
My First Ruby
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
 
Perl Fitxers i Directoris
Perl Fitxers i DirectorisPerl Fitxers i Directoris
Perl Fitxers i Directoris
 
Simplifying code monster to elegant in n 5 steps
Simplifying code  monster to elegant in n 5 stepsSimplifying code  monster to elegant in n 5 steps
Simplifying code monster to elegant in n 5 steps
 
Oo Perl
Oo PerlOo Perl
Oo Perl
 
MuseScore MusicHackDay Presentation
MuseScore MusicHackDay PresentationMuseScore MusicHackDay Presentation
MuseScore MusicHackDay Presentation
 
The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)The groovy puzzlers (as Presented at JavaOne 2014)
The groovy puzzlers (as Presented at JavaOne 2014)
 
Taking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order FunctionsTaking Perl to Eleven with Higher-Order Functions
Taking Perl to Eleven with Higher-Order Functions
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
 

Viewers also liked

Getfilestruct zbksh(1)
Getfilestruct zbksh(1)Getfilestruct zbksh(1)
Getfilestruct zbksh(1)
Ben Pope
 
Analysis of the Performance of Sea Level Stations at Haiti
Analysis of the Performance of Sea Level Stations at HaitiAnalysis of the Performance of Sea Level Stations at Haiti
Analysis of the Performance of Sea Level Stations at HaitiKaruska Matos-Horta
 
Firewall
FirewallFirewall
Firewall
Sher Rodriguez
 
Getfilestruct zbksh
Getfilestruct zbkshGetfilestruct zbksh
Getfilestruct zbksh
Ben Pope
 
An a z index of the bash commands
An a z index of the bash commandsAn a z index of the bash commands
An a z index of the bash commands
Ben Pope
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
Ben Pope
 
Applecmdlista zs
Applecmdlista zsApplecmdlista zs
Applecmdlista zs
Ben Pope
 
Stefanie Lopez Angel - PPP Final
Stefanie Lopez Angel - PPP FinalStefanie Lopez Angel - PPP Final
Stefanie Lopez Angel - PPP Final
Stefanie Lopez-Angel
 
Xz file-format-1.0.4
Xz file-format-1.0.4Xz file-format-1.0.4
Xz file-format-1.0.4
Ben Pope
 
An a z index of windows power shell commandss
An a z index of windows power shell commandssAn a z index of windows power shell commandss
An a z index of windows power shell commandss
Ben Pope
 
Compound var
Compound varCompound var
Compound var
Ben Pope
 
Cuadro sipnotico
Cuadro sipnoticoCuadro sipnotico
Cuadro sipnotico
thabata torrez perez
 
Pcad mision sucre
Pcad mision sucrePcad mision sucre
Pcad mision sucre
Lisanyis Alfonzo
 

Viewers also liked (15)

Getfilestruct zbksh(1)
Getfilestruct zbksh(1)Getfilestruct zbksh(1)
Getfilestruct zbksh(1)
 
Analysis of the Performance of Sea Level Stations at Haiti
Analysis of the Performance of Sea Level Stations at HaitiAnalysis of the Performance of Sea Level Stations at Haiti
Analysis of the Performance of Sea Level Stations at Haiti
 
Firewall
FirewallFirewall
Firewall
 
Getfilestruct zbksh
Getfilestruct zbkshGetfilestruct zbksh
Getfilestruct zbksh
 
Slowinski_Portfolio
Slowinski_PortfolioSlowinski_Portfolio
Slowinski_Portfolio
 
Diplom
DiplomDiplom
Diplom
 
An a z index of the bash commands
An a z index of the bash commandsAn a z index of the bash commands
An a z index of the bash commands
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
Applecmdlista zs
Applecmdlista zsApplecmdlista zs
Applecmdlista zs
 
Stefanie Lopez Angel - PPP Final
Stefanie Lopez Angel - PPP FinalStefanie Lopez Angel - PPP Final
Stefanie Lopez Angel - PPP Final
 
Xz file-format-1.0.4
Xz file-format-1.0.4Xz file-format-1.0.4
Xz file-format-1.0.4
 
An a z index of windows power shell commandss
An a z index of windows power shell commandssAn a z index of windows power shell commandss
An a z index of windows power shell commandss
 
Compound var
Compound varCompound var
Compound var
 
Cuadro sipnotico
Cuadro sipnoticoCuadro sipnotico
Cuadro sipnotico
 
Pcad mision sucre
Pcad mision sucrePcad mision sucre
Pcad mision sucre
 

Similar to Mkscript sh

Unix 1st sem lab programs a - VTU Karnataka
Unix 1st sem lab programs a - VTU KarnatakaUnix 1st sem lab programs a - VTU Karnataka
Unix 1st sem lab programs a - VTU Karnataka
iCreateWorld
 
Shell Scripts
Shell ScriptsShell Scripts
Shell ScriptsDr.Ravi
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
Manav Prasad
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
Tushar B Kute
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsSudharsan S
 
3output 2.pdf10282017 httpsuml.umassonline.netbbcsw.docx
3output 2.pdf10282017 httpsuml.umassonline.netbbcsw.docx3output 2.pdf10282017 httpsuml.umassonline.netbbcsw.docx
3output 2.pdf10282017 httpsuml.umassonline.netbbcsw.docx
tamicawaysmith
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting BasicsDr.Ravi
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
Workhorse Computing
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Geeks Anonymes
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Ashrith Mekala
 
10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language
Yaroslav Tkachenko
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ewout2
 
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntuMengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Alferizhy Chalter
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
Aleksandar Bilanovic
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scriptingerbipulkumar
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
Techvilla
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 

Similar to Mkscript sh (20)

Unix 5 en
Unix 5 enUnix 5 en
Unix 5 en
 
Unix 1st sem lab programs a - VTU Karnataka
Unix 1st sem lab programs a - VTU KarnatakaUnix 1st sem lab programs a - VTU Karnataka
Unix 1st sem lab programs a - VTU Karnataka
 
Shell Scripts
Shell ScriptsShell Scripts
Shell Scripts
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basics
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on Linux
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
3output 2.pdf10282017 httpsuml.umassonline.netbbcsw.docx
3output 2.pdf10282017 httpsuml.umassonline.netbbcsw.docx3output 2.pdf10282017 httpsuml.umassonline.netbbcsw.docx
3output 2.pdf10282017 httpsuml.umassonline.netbbcsw.docx
 
Unix Shell Scripting Basics
Unix Shell Scripting BasicsUnix Shell Scripting Basics
Unix Shell Scripting Basics
 
BASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic InterpolationBASH Variables Part 1: Basic Interpolation
BASH Variables Part 1: Basic Interpolation
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntuMengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
Mengembalikan data yang terhapus atau rusak pada hardisk menggunakan ubuntu
 
Unix tips and tricks
Unix tips and tricksUnix tips and tricks
Unix tips and tricks
 
2-introduction_to_shell_scripting
2-introduction_to_shell_scripting2-introduction_to_shell_scripting
2-introduction_to_shell_scripting
 
Bash Scripting Workshop
Bash Scripting WorkshopBash Scripting Workshop
Bash Scripting Workshop
 
Raspberry pi Part 25
Raspberry pi Part 25Raspberry pi Part 25
Raspberry pi Part 25
 
My shell
My shellMy shell
My shell
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 

More from Ben Pope

Programming collaborative-ref
Programming collaborative-refProgramming collaborative-ref
Programming collaborative-ref
Ben Pope
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 sh
Ben Pope
 
Pop3stat sh
Pop3stat shPop3stat sh
Pop3stat sh
Ben Pope
 
Phadd sh
Phadd shPhadd sh
Phadd sh
Ben Pope
 
Phdel sh
Phdel shPhdel sh
Phdel sh
Ben Pope
 
Menu func-sh
Menu func-shMenu func-sh
Menu func-sh
Ben Pope
 
Menu func-sh(1)
Menu func-sh(1)Menu func-sh(1)
Menu func-sh(1)
Ben Pope
 
Luhn sh
Luhn shLuhn sh
Luhn sh
Ben Pope
 

More from Ben Pope (8)

Programming collaborative-ref
Programming collaborative-refProgramming collaborative-ref
Programming collaborative-ref
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 sh
 
Pop3stat sh
Pop3stat shPop3stat sh
Pop3stat sh
 
Phadd sh
Phadd shPhadd sh
Phadd sh
 
Phdel sh
Phdel shPhdel sh
Phdel sh
 
Menu func-sh
Menu func-shMenu func-sh
Menu func-sh
 
Menu func-sh(1)
Menu func-sh(1)Menu func-sh(1)
Menu func-sh(1)
 
Luhn sh
Luhn shLuhn sh
Luhn sh
 

Recently uploaded

Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Boris Ziegler
 
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
bosssp10
 
Exploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social DreamingExploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social Dreaming
Nicola Wreford-Howard
 
-- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month ---- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month --
NZSG
 
Authentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto RicoAuthentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto Rico
Corey Perlman, Social Media Speaker and Consultant
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
Adam Smith
 
FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134
LR1709MUSIC
 
Mastering B2B Payments Webinar from BlueSnap
Mastering B2B Payments Webinar from BlueSnapMastering B2B Payments Webinar from BlueSnap
Mastering B2B Payments Webinar from BlueSnap
Norma Mushkat Gaffin
 
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdfSearch Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Arihant Webtech Pvt. Ltd
 
Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024
Kirill Klimov
 
Kseniya Leshchenko: Shared development support service model as the way to ma...
Kseniya Leshchenko: Shared development support service model as the way to ma...Kseniya Leshchenko: Shared development support service model as the way to ma...
Kseniya Leshchenko: Shared development support service model as the way to ma...
Lviv Startup Club
 
Set off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptxSet off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptx
HARSHITHV26
 
In the Adani-Hindenburg case, what is SEBI investigating.pptx
In the Adani-Hindenburg case, what is SEBI investigating.pptxIn the Adani-Hindenburg case, what is SEBI investigating.pptx
In the Adani-Hindenburg case, what is SEBI investigating.pptx
Adani case
 
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdfMeas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
dylandmeas
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.docBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
daothibichhang1
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdfBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
daothibichhang1
 
Premium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern BusinessesPremium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern Businesses
SynapseIndia
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
FelixPerez547899
 
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBdCree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
creerey
 
LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024
Lital Barkan
 

Recently uploaded (20)

Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
Agency Managed Advisory Board As a Solution To Career Path Defining Business ...
 
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
Call 8867766396 Satta Matka Dpboss Matka Guessing Satta batta Matka 420 Satta...
 
Exploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social DreamingExploring Patterns of Connection with Social Dreaming
Exploring Patterns of Connection with Social Dreaming
 
-- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month ---- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month --
 
Authentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto RicoAuthentically Social by Corey Perlman - EO Puerto Rico
Authentically Social by Corey Perlman - EO Puerto Rico
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
 
FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134
 
Mastering B2B Payments Webinar from BlueSnap
Mastering B2B Payments Webinar from BlueSnapMastering B2B Payments Webinar from BlueSnap
Mastering B2B Payments Webinar from BlueSnap
 
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdfSearch Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
 
Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024Organizational Change Leadership Agile Tour Geneve 2024
Organizational Change Leadership Agile Tour Geneve 2024
 
Kseniya Leshchenko: Shared development support service model as the way to ma...
Kseniya Leshchenko: Shared development support service model as the way to ma...Kseniya Leshchenko: Shared development support service model as the way to ma...
Kseniya Leshchenko: Shared development support service model as the way to ma...
 
Set off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptxSet off and carry forward of losses and assessment of individuals.pptx
Set off and carry forward of losses and assessment of individuals.pptx
 
In the Adani-Hindenburg case, what is SEBI investigating.pptx
In the Adani-Hindenburg case, what is SEBI investigating.pptxIn the Adani-Hindenburg case, what is SEBI investigating.pptx
In the Adani-Hindenburg case, what is SEBI investigating.pptx
 
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdfMeas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
Meas_Dylan_DMBS_PB1_2024-05XX_Revised.pdf
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.docBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdfBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc.pdf
 
Premium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern BusinessesPremium MEAN Stack Development Solutions for Modern Businesses
Premium MEAN Stack Development Solutions for Modern Businesses
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
 
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBdCree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
 
LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024LA HUG - Video Testimonials with Chynna Morgan - June 2024
LA HUG - Video Testimonials with Chynna Morgan - June 2024
 

Mkscript sh

  • 1. #!/bin/bash # /usr/local/bin/mkscript # Copyright 2000, Chris F.A. Johnson # Released under the terms of the GNU General Public License # USAGE: mkscript command # fix permissions for script "command"-sh in /usr/local/bin/scripts # create it if it doesn't exist # link it to "command" in /usr/local/bin die() { exitcode=$1 shift if [ "$*" ] then echo "$*" fi exit ${exitcode:-1} } version() { echo $version } usage() { echo " $progname - USAGE: $progname [OPTIONS] OPTIONS: -d DESC - description -f - force=1 ;; # replace file if it exists -r - remove=1 ;; # remove script if is exists -R - remove=2 ;; # not used -a OPTS - options that take arguments -o OPTS - options that do not take arguments -u - user=$OPTARG ;; -a OPTS - argopts=$OPTARG ;; -h - help: print this message -H - help: print more detailed message -v - verbose: -V - print version information Copyright 2001, Chris F.A. Johnson " } put_header() { echo "#!/bin/bash # `date` # NAME: $command # Copyright `date +%Y`, $author # Released under the terms of the GNU General Public License " } func_die()
  • 2. { echo 'die() { exitcode=$1 shift if [ "$*" ] then echo "$*" fi exit ${exitcode:-1} } ' } func_version() { echo 'version() { echo " $progname, version $version Copyright $copyright, $author $email This is free software, released under the terms of the GNU General Public License. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " } ' } func_usage() { echo "usage() { echo " $progname - $description USAGE: $progname [OPTIONS] OPTIONS: "" { n=0 while [ $n -lt ${#argopts} ] do l=${argopts:$n:1} echo " -$l arg - " n=$(( $n + 1 )) done n=0 while [ $n -lt ${#opts} ] do l=${opts:$n:1} echo " -$l - " n=$(( $n + 1 )) done } | sort echo " [ $longusage -eq 1 ] && echo " -h - help: print shorter help message -H - help: print this message" || echo " -h - help: print this message
  • 3. -H - help: print more detailed message" echo " -v - verbose: -V - print version information " [ $longusage -eq 1 ] && version || echo " Copyright $copyright, $author " } " } put_vars() { echo " description="$description" verbose=0 longusage=0 version="1.0" copyright=$copyright author="$author"" echo 'progname=${0##*/}' } put_getopts() { [ -n "$argopts" ] && { o=0 while [ $o -lt ${#argopts} ] do l=${argopts:$o:1} [ "$l" ] && getopts="$getopts${NL} $l) ${l}_arg=$OPTARG ;;" optstr=${optstr}${l}: o=$(( $o + 1 )) done } [ -n "$opts" ] && { o=0 while [ $o -lt ${#opts} ] do l=${opts:$o:1} [ "$l" ] && getopts="$getopts${NL} $l) ${l}_opt=1 ;;" optstr=${optstr}${l} o=$(( $o + 1 )) done } echo " while getopts vVhH-:$optstr var do case $var in" echo "$getopts" | sort echo ' -) case $OPTARG in
  • 4. help) usage; exit ;; help_long) longusage=1; usage; exit ;; version) version; exit ;; esac ;; h) usage; exit ;; H) longusage=1; usage; exit ;; v) verbose=$(( $verbose + 1 )) ;; V) version; exit ;; *);; esac done shift $(( $OPTIND - 1 )) ' } bindir="/usr/local/bin" shdir="${bindir}/scripts" version="1.1" verbose=0 force=0 remove=0 longusage=0 progname=${0##*/} NL=$'n' while getopts vVhHfro:a:d:u: var do case "$var" in d) description=$OPTARG ;; f) force=1 ;; # replace file if it exists r) remove=1 ;; R) remove=2 ;; a) argopts=$OPTARG ;; o) opts=$OPTARG ;; u) user=$OPTARG ;; a) argopts=$OPTARG ;; v) verbose=$(( $verbose + 1 )) ;; V) version; exit ;; h) usage; exit ;; H) longusage=1; usage; exit ;; *);; esac done shift $(( $OPTIND - 1 )) echo *=$* echo opts=$opts echo argopts=$argopts if [ ! "$1" ] then die 1 "${progname}: command name required" fi cd ${shdir} command=${1} shcommand=${command}-sh author="`grep -w ^$USER /etc/passwd | cut -d: -f5 | cut -d "," -f1`" copyright=`date +%Y`
  • 5. if [ $remove -ge 1 ] then if [ -f "$shcommand" -a $remove -eq 2 ] then rm -f $shcommand fi if [ -f $bindir/$command ] then rm -f $bindir/$command fi ## add code to remove any other aliases in /usr/local/bin exit fi if [ ! -f $bindir/$command ] then touch $shdir/$shcommand cd $bindir ln -s $shdir/$shcommand $command fi if [ -f "$shcommand" -a $force = 0 ];then echo " $shcommand already exists Use -f to replace it" exit fi ( put_header func_version func_usage put_vars { [ -n "$argopts" ] && { echo $argopts | while read -n1 l do [ "$l" ] && echo "${l}_arg=" done } [ -n "$opts" ] && { echo $opts | while read -n1 l do [ "$l" ] && echo "${l}_opt=0" done } } | sort put_getopts ) > ${shdir}/$shcommand chown ${user:-$USER} ${shdir}/$shcommand chmod a+x ${shdir}/${shcommand} cd $bindir pwd ln -fs scripts/$shcommand $command ls -l ${shdir}/$shcommand
  • 6. if [ $remove -ge 1 ] then if [ -f "$shcommand" -a $remove -eq 2 ] then rm -f $shcommand fi if [ -f $bindir/$command ] then rm -f $bindir/$command fi ## add code to remove any other aliases in /usr/local/bin exit fi if [ ! -f $bindir/$command ] then touch $shdir/$shcommand cd $bindir ln -s $shdir/$shcommand $command fi if [ -f "$shcommand" -a $force = 0 ];then echo " $shcommand already exists Use -f to replace it" exit fi ( put_header func_version func_usage put_vars { [ -n "$argopts" ] && { echo $argopts | while read -n1 l do [ "$l" ] && echo "${l}_arg=" done } [ -n "$opts" ] && { echo $opts | while read -n1 l do [ "$l" ] && echo "${l}_opt=0" done } } | sort put_getopts ) > ${shdir}/$shcommand chown ${user:-$USER} ${shdir}/$shcommand chmod a+x ${shdir}/${shcommand} cd $bindir pwd ln -fs scripts/$shcommand $command ls -l ${shdir}/$shcommand