SlideShare a Scribd company logo
1 of 6
#!/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 regexbrian d foy
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate shBen Pope
 
WordPress Cuztom Helper
WordPress Cuztom HelperWordPress Cuztom Helper
WordPress Cuztom Helperslicejack
 
2014 database - course 2 - php
2014 database - course 2 - php2014 database - course 2 - php
2014 database - course 2 - phpHung-yu Lin
 
Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Shell实现的windows回收站功能的脚本
Shell实现的windows回收站功能的脚本Lingfei Kong
 
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: HackVic 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 Directorisfrankiejol
 
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 stepstutec
 
MuseScore MusicHackDay Presentation
MuseScore MusicHackDay PresentationMuseScore MusicHackDay Presentation
MuseScore MusicHackDay PresentationMuseScore
 
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 FunctionsDavid 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 hadoopQuỳ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
 
Getfilestruct zbksh
Getfilestruct zbkshGetfilestruct zbksh
Getfilestruct zbkshBen 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 commandsBen Pope
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs shBen Pope
 
Applecmdlista zs
Applecmdlista zsApplecmdlista zs
Applecmdlista zsBen Pope
 
Xz file-format-1.0.4
Xz file-format-1.0.4Xz file-format-1.0.4
Xz file-format-1.0.4Ben 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 commandssBen Pope
 
Compound var
Compound varCompound var
Compound varBen Pope
 

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 KarnatakaiCreateWorld
 
Shell Scripts
Shell ScriptsShell Scripts
Shell ScriptsDr.Ravi
 
Unix shell scripting basics
Unix shell scripting basicsUnix shell scripting basics
Unix shell scripting basicsManav Prasad
 
Module 03 Programming on Linux
Module 03 Programming on LinuxModule 03 Programming on Linux
Module 03 Programming on LinuxTushar 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.docxtamicawaysmith
 
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 InterpolationWorkhorse Computing
 
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 languageYaroslav Tkachenko
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaewout2
 
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 ubuntuAlferizhy Chalter
 
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 25Techvilla
 
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-refBen Pope
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 shBen Pope
 
Pop3stat sh
Pop3stat shPop3stat sh
Pop3stat shBen Pope
 
Menu func-sh
Menu func-shMenu func-sh
Menu func-shBen Pope
 
Menu func-sh(1)
Menu func-sh(1)Menu func-sh(1)
Menu func-sh(1)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

Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Riya Pathan
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...lizamodels9
 
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607dollysharma2066
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCRashishs7044
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMintel Group
 
Call Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any TimeCall Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any Timedelhimodelshub1
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchirictsugar
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCRashishs7044
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfJos Voskuil
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...lizamodels9
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxMarkAnthonyAurellano
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africaictsugar
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCRashishs7044
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailAriel592675
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...lizamodels9
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy Verified Accounts
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 

Recently uploaded (20)

Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
 
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
(Best) ENJOY Call Girls in Faridabad Ex | 8377087607
 
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR8447779800, Low rate Call girls in Tughlakabad Delhi NCR
8447779800, Low rate Call girls in Tughlakabad Delhi NCR
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 Edition
 
Call Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any TimeCall Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any Time
 
Marketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent ChirchirMarketplace and Quality Assurance Presentation - Vincent Chirchir
Marketplace and Quality Assurance Presentation - Vincent Chirchir
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
 
Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdf
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africa
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
 
Corporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information TechnologyCorporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information Technology
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 
Case study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detailCase study on tata clothing brand zudio in detail
Case study on tata clothing brand zudio in detail
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
 
Buy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail AccountsBuy gmail accounts.pdf Buy Old Gmail Accounts
Buy gmail accounts.pdf Buy Old Gmail Accounts
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 

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