SlideShare a Scribd company logo
1 of 21
Download to read offline
The myth of the
small script
Mario A. Santini - Full Stack Developer
JUG TAA
The Mith Of The Small Script
This is a story about how what seemed a simple
problem, actually is rather complicated
A New Task
• Your boss: “Please, write a small script that
prints out the 3rd and the 5th column of this
file.”
• Your boss: “Keep in mind, I need it: ASAP!”
Have A Deep Look At The
Task
• Looks as an easy and short task, but actually you
missed some important infos.
• Most of the requirements or client expectations
arrive like this.
• It is simple for your boss, just because it’s easy to
explain. Of course if you don’t go deep inside the
details.
Actually software is made by details!
Remember, We Don’t Have
Time
• On those situations it is better for you to go
back to your boss with something to show, and
not with something to ask about.
• So we guess the missed details and do our best!
The Script - Requirements
• We know we have a text file divided in columns
to parse
• We guess the files are on a Linux server
• We guess just to printout the result
• The fast and easy way is to write a very short
shell script in bash
The Script - The Code
$ cat ./my_short_script.sh <<EOF
> #!/bin/bash
>
> data="./data"
>
> cut -f 3,5 -d , ${data}/$1
>
> EOF
$ chmod a+x ./my_short_script.sh
>>> Test it!
$ ./my_short_script.sh the_file_to_compute.cv
head3,head5
field3,field5
field3,field5
field3,field5
field3,field5
field3,field5
field3,field5
field3,field5
field3,field5
…
Pretty easy, pretty fast!
The Script Doesn’t Work!
• Your boss: “Sorry, I launched your script and got
an error: “
cut: Error reading ./data/
… after a complicated interview with your boss…
• You: “You miss the parameter, that’s why the script fail”
• Your boss: “Sorry man, I don’t know anything about a
parameter”
The First Amendment
• Add a simple help
• Check if the data file is in input, if not print the
help
You don’t know how
people will use your code!
The First Amendment
$ cat ./my_short_script_v2.sh
#!/bin/bash
function help {
echo "Please run the script as follow example:"
echo ""
echo "$ $1 <data_file_name>"
echo ""
echo "<data_file_name>: as the name of a csv file in data folder"
echo ""
echo ""
}
if [ "$#" -ne 1 ]; then
help $0;
exit 0
fi
data="./data"
cut -f 3,5 -d , ${data}/$1
The Second Amendment
• Your boss: “It works with few files, but some times I
got an error, could you have a look please?”
• After a little investigation you have:
• your script doesn’t support fields that contains the
field separator, even if they are quoted and valid
csv files;
• your script doesn’t support different field
separator characters.
Now Works But…
• Your boss: “In some files, we need to print out
the 2nd and the 4th columns, instead of the 3rd
and the 5th.”
Things changes!
A New Improovement
• Your boss: “I would like to work at home, but I
don’t have any other Unix like Oss there.”
Possible Solutions
• Docker / Vagrant
… it’s a bunch of gigs and more headaches for the future…
• Cygwin…
No thanks… too complicated for my boss.
The better solution is to re-write your script in a way that it is more
easy to manage:
use a general purpose programming language like Java
( Of course you could use your preferred language to, but remember, we are a Jug! ;) )
What “Like Java” means
• a powerful general purpose language
• could run on many different operating systems
without needs of changes on the source code
• have a long list of available libraries that helps
writing less code and doing things fast and safe
• supported from a wide and huge community
• Last but not last: to be Open Source, better if FOSS
What We Need
In order to re-write the script in Java, we could
even use a short cut by including useful libraries:
• A lib to handle csv files
• A lib to handle command line options
• An installing framework tool
• A lib for log
Conclusions
In the real word you never have something as “a
small script”.
Even if you are a developer like me, and you have
your HD full of small scripts doing everything you
need to be done.
Conclusions 2
The scripts you write for yourself are simple
because you don’t have to deal with many choices,
you just design it as it perfectly fits your needs.
And more, you fits the world to fits your script.
If your needs will changes, you know it and you’ll
change the scripts first or adapt the environment
as convenient.
Conclusion 3
Don’t be afraid to use general purpose languages
like Java.
They are so widely spread because you could use it
for short programs, like the one we shown you, to
very complicated systems made by millions of line
of code.
So think it easy and simple as KISS wants, but not
be trivial.
The Java Version
https://github.com/alexmario74/jcut
Thank you!

More Related Content

Viewers also liked

Unit 11 analysis of scripts
Unit 11  analysis of scriptsUnit 11  analysis of scripts
Unit 11 analysis of scriptselliottickle
 
Story board of example script
Story board of example scriptStory board of example script
Story board of example scriptflickham
 
Bachelor Thesis Presentation (Italian)
Bachelor Thesis Presentation (Italian)Bachelor Thesis Presentation (Italian)
Bachelor Thesis Presentation (Italian)Jovan Stevovic
 
Script for short film analysis
Script for short film analysisScript for short film analysis
Script for short film analysisAdrianna Paniak
 
Short film script presentation
Short film script presentationShort film script presentation
Short film script presentationashhillfilm
 
Dakilang mangingibig.script
Dakilang mangingibig.scriptDakilang mangingibig.script
Dakilang mangingibig.scriptDASeries
 
Fast Love - Comedy Short Film Script
Fast Love - Comedy Short Film ScriptFast Love - Comedy Short Film Script
Fast Love - Comedy Short Film ScriptLloyder
 
Abhishek group script of role play
Abhishek group script of role playAbhishek group script of role play
Abhishek group script of role playRiya Sinha
 
roleplay in the classroom
roleplay in the classroomroleplay in the classroom
roleplay in the classroomafricahi
 
Anatomy of maxilla and mandible
Anatomy of maxilla and mandibleAnatomy of maxilla and mandible
Anatomy of maxilla and mandibleFardan Qadeer
 

Viewers also liked (19)

Lambda architecture
Lambda architectureLambda architecture
Lambda architecture
 
Docker jug taa
Docker   jug taaDocker   jug taa
Docker jug taa
 
Short film script
Short film scriptShort film script
Short film script
 
Planning the cast
Planning the castPlanning the cast
Planning the cast
 
Unit 11 analysis of scripts
Unit 11  analysis of scriptsUnit 11  analysis of scripts
Unit 11 analysis of scripts
 
Lottery choice
Lottery choiceLottery choice
Lottery choice
 
Story board of example script
Story board of example scriptStory board of example script
Story board of example script
 
Short film script
Short film scriptShort film script
Short film script
 
Bachelor Thesis Presentation (Italian)
Bachelor Thesis Presentation (Italian)Bachelor Thesis Presentation (Italian)
Bachelor Thesis Presentation (Italian)
 
Script for short film analysis
Script for short film analysisScript for short film analysis
Script for short film analysis
 
Script Example
Script ExampleScript Example
Script Example
 
How To Write A Great Corporate Video Script
How To Write A Great Corporate Video ScriptHow To Write A Great Corporate Video Script
How To Write A Great Corporate Video Script
 
Short film script presentation
Short film script presentationShort film script presentation
Short film script presentation
 
Troy script
Troy scriptTroy script
Troy script
 
Dakilang mangingibig.script
Dakilang mangingibig.scriptDakilang mangingibig.script
Dakilang mangingibig.script
 
Fast Love - Comedy Short Film Script
Fast Love - Comedy Short Film ScriptFast Love - Comedy Short Film Script
Fast Love - Comedy Short Film Script
 
Abhishek group script of role play
Abhishek group script of role playAbhishek group script of role play
Abhishek group script of role play
 
roleplay in the classroom
roleplay in the classroomroleplay in the classroom
roleplay in the classroom
 
Anatomy of maxilla and mandible
Anatomy of maxilla and mandibleAnatomy of maxilla and mandible
Anatomy of maxilla and mandible
 

Similar to The myth of the "small script

Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsAndrew McNicol
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013Iván Montes
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11Derek Jacoby
 
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...panagenda
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.pptRehnawilson1
 
PASS 24HOP Linux Scripting Tips and Tricks
PASS 24HOP Linux Scripting Tips and TricksPASS 24HOP Linux Scripting Tips and Tricks
PASS 24HOP Linux Scripting Tips and TricksKellyn Pot'Vin-Gorman
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Andrei KUCHARAVY
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesJohn Coggeshall
 
The View - The top 30 Development tips
The View - The top 30 Development tipsThe View - The top 30 Development tips
The View - The top 30 Development tipsBill Buchan
 
Week 5
Week 5Week 5
Week 5A VD
 
Week 5
Week 5Week 5
Week 5A VD
 
Improve your SQL workload with observability
Improve your SQL workload with observabilityImprove your SQL workload with observability
Improve your SQL workload with observabilityOVHcloud
 
Metaprogramming Go
Metaprogramming GoMetaprogramming Go
Metaprogramming GoWeng Wei
 
Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systemsBill Buchan
 

Similar to The myth of the "small script (20)

Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security Professionals
 
Programming Languages #devcon2013
Programming Languages #devcon2013Programming Languages #devcon2013
Programming Languages #devcon2013
 
ACM Init() lesson 1
ACM Init() lesson 1ACM Init() lesson 1
ACM Init() lesson 1
 
Untangling spring week11
Untangling spring week11Untangling spring week11
Untangling spring week11
 
Git Makes Me Angry Inside
Git Makes Me Angry InsideGit Makes Me Angry Inside
Git Makes Me Angry Inside
 
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
 
Vimperl
VimperlVimperl
Vimperl
 
miniproject.pptx
miniproject.pptxminiproject.pptx
miniproject.pptx
 
Python Programming1.ppt
Python Programming1.pptPython Programming1.ppt
Python Programming1.ppt
 
PASS 24HOP Linux Scripting Tips and Tricks
PASS 24HOP Linux Scripting Tips and TricksPASS 24HOP Linux Scripting Tips and Tricks
PASS 24HOP Linux Scripting Tips and Tricks
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
 
Apache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 MistakesApache Con 2008 Top 10 Mistakes
Apache Con 2008 Top 10 Mistakes
 
The View - The top 30 Development tips
The View - The top 30 Development tipsThe View - The top 30 Development tips
The View - The top 30 Development tips
 
Week 5
Week 5Week 5
Week 5
 
Week 5
Week 5Week 5
Week 5
 
Improve your SQL workload with observability
Improve your SQL workload with observabilityImprove your SQL workload with observability
Improve your SQL workload with observability
 
Metaprogramming Go
Metaprogramming GoMetaprogramming Go
Metaprogramming Go
 
First app
First appFirst app
First app
 
Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systems
 
Lug
LugLug
Lug
 

More from Mario Alexandro Santini (7)

A Safe Dock for our Programs
A Safe Dock for our ProgramsA Safe Dock for our Programs
A Safe Dock for our Programs
 
Rust With async / .await
Rust With async / .awaitRust With async / .await
Rust With async / .await
 
Rust_Threads.pdf
Rust_Threads.pdfRust_Threads.pdf
Rust_Threads.pdf
 
The_Borrow_Checker.pdf
The_Borrow_Checker.pdfThe_Borrow_Checker.pdf
The_Borrow_Checker.pdf
 
Vuejs
VuejsVuejs
Vuejs
 
The Rust Programming Language
The Rust Programming LanguageThe Rust Programming Language
The Rust Programming Language
 
Introduction to typescript
Introduction to typescriptIntroduction to typescript
Introduction to typescript
 

Recently uploaded

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 

Recently uploaded (20)

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 

The myth of the "small script

  • 1. The myth of the small script Mario A. Santini - Full Stack Developer JUG TAA
  • 2. The Mith Of The Small Script This is a story about how what seemed a simple problem, actually is rather complicated
  • 3. A New Task • Your boss: “Please, write a small script that prints out the 3rd and the 5th column of this file.” • Your boss: “Keep in mind, I need it: ASAP!”
  • 4. Have A Deep Look At The Task • Looks as an easy and short task, but actually you missed some important infos. • Most of the requirements or client expectations arrive like this. • It is simple for your boss, just because it’s easy to explain. Of course if you don’t go deep inside the details. Actually software is made by details!
  • 5. Remember, We Don’t Have Time • On those situations it is better for you to go back to your boss with something to show, and not with something to ask about. • So we guess the missed details and do our best!
  • 6. The Script - Requirements • We know we have a text file divided in columns to parse • We guess the files are on a Linux server • We guess just to printout the result • The fast and easy way is to write a very short shell script in bash
  • 7. The Script - The Code $ cat ./my_short_script.sh <<EOF > #!/bin/bash > > data="./data" > > cut -f 3,5 -d , ${data}/$1 > > EOF $ chmod a+x ./my_short_script.sh >>> Test it! $ ./my_short_script.sh the_file_to_compute.cv head3,head5 field3,field5 field3,field5 field3,field5 field3,field5 field3,field5 field3,field5 field3,field5 field3,field5 … Pretty easy, pretty fast!
  • 8. The Script Doesn’t Work! • Your boss: “Sorry, I launched your script and got an error: “ cut: Error reading ./data/ … after a complicated interview with your boss… • You: “You miss the parameter, that’s why the script fail” • Your boss: “Sorry man, I don’t know anything about a parameter”
  • 9. The First Amendment • Add a simple help • Check if the data file is in input, if not print the help You don’t know how people will use your code!
  • 10. The First Amendment $ cat ./my_short_script_v2.sh #!/bin/bash function help { echo "Please run the script as follow example:" echo "" echo "$ $1 <data_file_name>" echo "" echo "<data_file_name>: as the name of a csv file in data folder" echo "" echo "" } if [ "$#" -ne 1 ]; then help $0; exit 0 fi data="./data" cut -f 3,5 -d , ${data}/$1
  • 11. The Second Amendment • Your boss: “It works with few files, but some times I got an error, could you have a look please?” • After a little investigation you have: • your script doesn’t support fields that contains the field separator, even if they are quoted and valid csv files; • your script doesn’t support different field separator characters.
  • 12. Now Works But… • Your boss: “In some files, we need to print out the 2nd and the 4th columns, instead of the 3rd and the 5th.” Things changes!
  • 13. A New Improovement • Your boss: “I would like to work at home, but I don’t have any other Unix like Oss there.”
  • 14. Possible Solutions • Docker / Vagrant … it’s a bunch of gigs and more headaches for the future… • Cygwin… No thanks… too complicated for my boss. The better solution is to re-write your script in a way that it is more easy to manage: use a general purpose programming language like Java ( Of course you could use your preferred language to, but remember, we are a Jug! ;) )
  • 15. What “Like Java” means • a powerful general purpose language • could run on many different operating systems without needs of changes on the source code • have a long list of available libraries that helps writing less code and doing things fast and safe • supported from a wide and huge community • Last but not last: to be Open Source, better if FOSS
  • 16. What We Need In order to re-write the script in Java, we could even use a short cut by including useful libraries: • A lib to handle csv files • A lib to handle command line options • An installing framework tool • A lib for log
  • 17. Conclusions In the real word you never have something as “a small script”. Even if you are a developer like me, and you have your HD full of small scripts doing everything you need to be done.
  • 18. Conclusions 2 The scripts you write for yourself are simple because you don’t have to deal with many choices, you just design it as it perfectly fits your needs. And more, you fits the world to fits your script. If your needs will changes, you know it and you’ll change the scripts first or adapt the environment as convenient.
  • 19. Conclusion 3 Don’t be afraid to use general purpose languages like Java. They are so widely spread because you could use it for short programs, like the one we shown you, to very complicated systems made by millions of line of code. So think it easy and simple as KISS wants, but not be trivial.